Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to pass one query result to another query
Message
 
 
To
21/05/2011 07:44:54
Mazahir Naya
Kuwait United Co.
Kuwait, Kuwait
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01511345
Message ID:
01511373
Views:
53
>Dear All UT Group members
>hi to all after such a long time.
>i would like to know how to pass one query result on 2nd query as a Paramtetr.
>for example hear is the my Query.
>
>1st Query :-
> Select * from Employee_v as Emp
>Note:- Bring all information from Employee Table
>
>2nd Query :-
> select TOCID from sab.dbo.propval AS B
> where B.prop_id = 41 and str_val = emp.empid
>Note:- Table call Propval query bring data only related to respected Employee
>
>3rd Steps:-
>
> Update sab.dbo.propval set str_val = emp.Title
> WHERE TOCID = b.tocid AND prop_id=42
> update the Propval table row as per the requierment.
>
>so need a help is the my qery syntex is correct or requier to update.
>
>Best Regards
>Mazahir

In SQL 2005+ you can try the following:
;with cte as (select P.TocID, P.Str_Val, E.Title 
from Sab.dbo.PropVal P inner join Employee_v E 
ON P.Str_Val = E.EmpID 
where P.Prop_ID = 41)

UPDATE P set Str_Val = c.Title
from Sab.dbo.PropVal P inner join cte C on P.TocID = c.TocID
where P.Prop_ID = 42
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform