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 |
|
jamie
Aged Yak Warrior
542 Posts |
Posted - 2008-04-30 : 04:19:49
|
| hi, what am I doing wrong here :declare @heading varcharSET @heading = 'Today'select case when @heading = 'Today' THEN select getdate() as [date]end |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-30 : 04:24:13
|
declare @heading varcharSET @heading = 'Today'select case when @heading = 'Today' THENgetdate() end as [date] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-30 : 04:24:44
|
declare @heading varcharSET @heading = 'Today'select case @heading when 'Today' THEN getdate() end as [date] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-30 : 04:25:09
|
quote: Originally posted by jamie hi, what am I doing wrong here :declare @heading varchar(length)SET @heading = 'Today'select case when @heading = 'Today' THEN select getdate() as [date] end
two things.1.You need to specify length for varchar variable2.You dont need select in red |
 |
|
|
jamie
Aged Yak Warrior
542 Posts |
Posted - 2008-04-30 : 04:29:05
|
| thanks guys, I ll try those suggestions. |
 |
|
|
jamie
Aged Yak Warrior
542 Posts |
Posted - 2008-04-30 : 04:31:26
|
| ok, that works.however, how about :declare @heading varcharSET @heading = 'people'select case when @heading = 'people' THENselect * from peopleend select case when @heading = 'accounts' THENselect * from accountsend |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-30 : 04:33:41
|
[code]declare @heading varchar(20)SET @heading = 'people'IF @heading = 'people' select * from peopleIF @heading = 'accounts' select * from accounts[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
jamie
Aged Yak Warrior
542 Posts |
Posted - 2008-04-30 : 04:35:19
|
| THANKS ! I didn't know I could use IF in T-SQL ! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-30 : 09:14:24
|
quote: Originally posted by jamie ok, that works.however, how about :declare @heading varcharSET @heading = 'people'select case when @heading = 'people' THENselect * from peopleend select case when @heading = 'accounts' THENselect * from accountsend
Vishak already pointed out that you should use length for your varchar datatypeAlso referhttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|