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
 Help

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-10-02 : 07:56:20
NAndu writes "Hello sir,
I want some help...
set @var='[Channel ' + Convert (nvarchar(2),sum(@aint)) + ']'
select @Channel = @var from database1 where [station Address] = '1'
I want @var should be considered as column name.And value of yhat column is set to the @channel variable..."

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-10-02 : 08:20:34
http://www.sommarskog.se/dynamic_sql.html

Chirag
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-02 : 09:09:15
SELECT SUM(CASE @Channel
WHEN 1 THEN [Channel 1]
WHEN 2 THEN [Channel 2]
WHEN 3 THEN [Channel 3]
WHEN 4 THEN [Channel 4]
END)
FROM Database1
WHERE [Station Address] = '1'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-02 : 09:27:41
Why do you use Dynamic SQL?
If you are trying Cross tab, then read about Cross-tab Reports in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -