Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to pass one query result to another query
Message
 
 
À
21/05/2011 07:44:54
Mazahir Naya
Kuwait United Co.
Kuwait, Kuwait
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01511345
Message ID:
01511373
Vues:
54
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform