Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-12-12 : 07:30:27
|
| Hi in the stored Procedure i would get multiple values concatenated for a single variable..i want to insert mulitples records using the values in this variable I'm trying to bulid a query something like thisINSERT INTO TEmployee_System_Role (Role_NBR,Create_DT,Employee_NBR) VALUES (@Role_NBR,GETDATE(),(select employee_nbr from tEmployee where employee_nbr in (@employee_numbers))The error i receive isSubqueries are not allowed in this context. Only scalar expressions are allowed. Is there any way to do this... Please Suggest Me..Thanks Before Hand |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-12-12 : 08:34:33
|
INSERT INTO TEmployee_System_Role (Role_NBR,Create_DT,Employee_NBR)SELECT @Role_NBR,GETDATE(),employee_nbr from tEmployee where employee_nbr in (@employee_numbers))you can't do that in a where clause, you'll have to parse the valuessearch this site ParseValues to get some ideas on howJim |
 |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-12-12 : 09:13:35
|
| But i would be getting multiple values for employee numbersthe variable will be holding values like '1,2,3,4,5,6,7,8,9,10' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-12 : 09:21:51
|
| [code]INSERT INTO TEmployee_System_Role (Role_NBR,Create_DT,Employee_NBR)SELECTY @Role_NBR,GETDATE(), employee_nbr from tEmployee where ','+ @employee_numbers +',' LIKE '%,'+ CAST(employee_nbr AS varchar(20)) + ',%'[/code] |
 |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-12-12 : 10:15:51
|
Exactly... Its Working Fine.... Thanks a Lot VIshakh... Cant Stop Applauding youI dint Expect that it would be so simple.. I was breaking my head on this since long |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-12 : 10:25:41
|
No problem...you're welcome |
 |
|
|
|
|
|
|
|