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 |
|
ann06
Posting Yak Master
171 Posts |
Posted - 2008-11-29 : 03:20:35
|
| i want to do this parameterized queryDeclare @strQuery nvarchar(1000)Select @strQuery = 'Select E.EmpName, TS.Day, TS.HrsPutfrom dbo.empdetails E, dbo.EmpTimeSheet TSwhere E.EmpID = @emppid and TS.EmpID = @EmpID'Exec sp_executesql @strQuery, N'@emppid int',N'@EmpID int',@emppid=2,@EmpID=1it is giving this errorMust declare the variable '@EmpID'.if i have one parameter its working for 2 its not |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-11-29 : 03:53:11
|
I don't think that qualifies as a "parametrized query".Let me ask you one thing; why have you even considered dynamic sql for this query?SELECT e.EmpName, ts.[Day], ts.HrsPutFROM dbo.empDetails AS eINNER JOIN dbo.EmpTimeSheet AS ts ON ts.EmpID = @EmpIDWHERE e.EmpID = @emppid E 12°55'05.63"N 56°04'39.26" |
 |
|
|
ann06
Posting Yak Master
171 Posts |
Posted - 2008-11-29 : 04:25:03
|
| just for information :D but i figured it out it should be in this form Declare @strQuery nvarchar(1000)Select @strQuery = 'Select E.EmpName, TS.Day, TS.HrsPutfrom dbo.empdetails E, dbo.EmpTimeSheet TSwhere E.EmpID = @emppid and TS.EmpID = @EmpID'Exec sp_executesql @strQuery, N'@emppid int, @EmpID int',@emppid=2,@EmpID=1N'@emppid int, @EmpID int' ---- not N'@emppid int',N'@EmpID int'thanks for your time |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-11-29 : 07:46:05
|
| you have completely missed the point. Look at Peso's post. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-29 : 08:16:44
|
quote: Originally posted by ann06 just for information :D but i figured it out it should be in this form Declare @strQuery nvarchar(1000)Select @strQuery = 'Select E.EmpName, TS.Day, TS.HrsPutfrom dbo.empdetails E, dbo.EmpTimeSheet TSwhere E.EmpID = @emppid and TS.EmpID = @EmpID'Exec sp_executesql @strQuery, N'@emppid int, @EmpID int',@emppid=2,@EmpID=1N'@emppid int, @EmpID int' ---- not N'@emppid int',N'@EmpID int'thanks for your time
there's no condition which demands use of dynamic sql in above case. Thats exactly what peso suggested. The code given by Peso is what you exactly want. |
 |
|
|
|
|
|
|
|