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 |
|
ryanlcs
Yak Posting Veteran
62 Posts |
Posted - 2009-09-08 : 20:45:48
|
| HiI got 2 Set of command:Statement 1:Select @result = Count(Rec_Id) FROM Table1 Where Rec_Id = 2Update #Tmp_Tbl_Table2 Set Series_Value1 = @resultStatement 2:Exec(@Series_Formula1)Update #Tmp_Tbl_Table2 Set Series_Value1 = @resultIn statement 2, the variable @Series_Formula1 is assigned with "Select @result = Count(Rec_Id) FROM Table1 Where Rec_Id = 2" (retrieve from DB), which is exactly same as statement 1 line 1, somehow, it says that "Must declare the scalar variable "@result"".Please help. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ryanlcs
Yak Posting Veteran
62 Posts |
Posted - 2009-09-08 : 20:57:04
|
| Of course I have my variable declaration and GO command, cos the problem now is that the differences between the 2 statement I posted. So, I would focus on those 2 statement. |
 |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-09-09 : 09:19:35
|
| 1 if you have DECLARE @result ........ 1st statement ................. GO ...........2nd statement......... the result variable is gone2 your dynamic sql stored in @Series_Formula1 doesn't know the scalar variable @resultif you have @Series_Formula1 = 'Select @result = Count(Rec_Id) FROM Table1 Where Rec_Id = 2'and then you do EXEC(@Series_Formula1) this will never worksearch BOL for sp_exectesql |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|