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
 General SQL Server Forums
 New to SQL Server Programming
 I need to dynamic column name

Author  Topic 

atulbharadwaj
Starting Member

11 Posts

Posted - 2009-12-16 : 02:14:00
Create PROCEDURE [dbo].test
@Quarter varchar(100),
@Sector varchar(100),
@CurrentYear varchar(100)

AS
BEGIN
SET NOCOUNT ON;

select isnull(sum(@Quarter),0) as @Quarter FROM CompanyClassification INNER JOIN
QuarterlyCapitalisation ON BSC_CODE=BSC_CODE WHERE
SECTOR =@Sector AND @Quarter!=0 AND YEAR= @CurrentYear

end

its throwing error: Must declare the scalar variable "@Quarter".

atul

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-16 : 03:28:06
not possible except using Dynamic SQL

see http://www.sommarskog.se/dynamic_sql.html

see my comments on your the other thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=137226

and this is also a dup post of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=137247


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -