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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Store value in a variable using an exec

Author  Topic 

charul
Starting Member

18 Posts

Posted - 2009-01-09 : 07:13:52
I have a statement like this
Set @strSql= 'Select @Weightage= OCW_Weightage from PMS_OrgLevelCompWeightage,PMS_OrgLevelCompConfig
where OCW_CU_ID=@CUID and OCW_OCC_ID=OCC_ID '
exec (@strSql)

whenever i run this query i get an error saying
@Weightage not defined. how to solve this?

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-09 : 07:24:33
u can't use @weightage use
Set @strSql= 'Select OCW_Weightage from PMS_OrgLevelCompWeightage,PMS_OrgLevelCompConfig
where OCW_CU_ID=@CUID and OCW_OCC_ID=OCC_ID '
exec (@strSql)
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-09 : 07:27:47
quote:
Originally posted by charul

I have a statement like this
Set @strSql= 'Select @Weightage= OCW_Weightage from PMS_OrgLevelCompWeightage,PMS_OrgLevelCompConfig
where OCW_CU_ID=@CUID and OCW_OCC_ID=OCC_ID '
exec (@strSql)

whenever i run this query i get an error saying
@Weightage not defined. how to solve this?



Wrong method to do this,,,its never like this,,,,,
Set @strSql= 'Select @Weightage=
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-01-09 : 07:28:59
The next error will be: @CUID not defined


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 08:33:11
quote:
Originally posted by charul

I have a statement like this
Set @strSql= 'Select @Weightage= OCW_Weightage from PMS_OrgLevelCompWeightage,PMS_OrgLevelCompConfig
where OCW_CU_ID=@CUID and OCW_OCC_ID=OCC_ID '
exec (@strSql)

whenever i run this query i get an error saying
@Weightage not defined. how to solve this?


for returning values like this through dynbamic sql use sp_executesql instead of EXEC

http://technet.microsoft.com/en-us/library/ms188001.aspx
Go to Top of Page
   

- Advertisement -