Help with SQL?

Open discussion about any topic, as long as you abide by the rules of course!
Post Reply
Turbanator
Posts: 883
Joined: Wed Jun 08, 1983 7:00 am

Help with SQL?

Post by Turbanator »

i think this is actually really straight forward and simple, but lets see

Code: Select all

SELECT 
	page_id, 
	page_name, 
	file_name, 
	access_desc, 
	is_tab, 
	is_admin
FROM 	dbo.pages 
INNER JOIN dbo.access_levels ON pages.access_level=access_levels.access_level


UPDATE 	dbo.pages
SET 	page_name=@page_name,
	file_name=@file_name,
	is_tab=@is_tab,
	is_admin=@is_admin
Above i have my select query and an incomplete update query. Incomplete because I need to update page.access_level but I'm only providing access_levels.access_desc (reverse that of the select query).

So two tables, pages and access_levels. access_level is primary key in access_levels and foreign key in pages. how do I update when i only have @access_desc?
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post by dmmh »

maybe I am way of and misunderstanding you but why not do it like this?

Code: Select all

SELECT
   page_id,
   page_name,
   file_name,
   access_desc,
   access_level,
   is_tab,
   is_admin
FROM    dbo.pages
INNER JOIN dbo.access_levels ON pages.access_level=access_levels.access_level


UPDATE    dbo.pages
SET    page_name=@page_name,
   file_name=@file_name,
   is_tab=@is_tab,
   is_admin=@is_admin
   access_level=@access_level
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Post Reply