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 2008 Forums
 Transact-SQL (2008)
 CASE statement

Author  Topic 

dmaxj
Posting Yak Master

174 Posts

Posted - 2010-07-09 : 11:02:37
Why am I getting an error Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '='.
My code follows:

SELECT 'Production' AS Environment, 
@@SERVERNAME AS [Server] =
CASE [Server]
WHEN 'SQL01' THEN 'SQL01.HOME.ORG'
END,
loginname, sysadmin
FROM syslogins
ORDER BY loginname

Regards

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-09 : 11:05:27
[code]SELECT 'Production' AS Environment,
[Server] =
CASE [Server]
WHEN 'SQL01' THEN 'SQL01.HOME.ORG'
END,
loginname, sysadmin
FROM syslogins
ORDER BY loginname

[/code]

Madhivanan

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

dmaxj
Posting Yak Master

174 Posts

Posted - 2010-07-09 : 11:14:06
Hmmm - that code give the expected error :

Msg 207, Level 16, State 1, Line 3
Invalid column name 'Server'.

Thanks
Go to Top of Page

dmaxj
Posting Yak Master

174 Posts

Posted - 2010-07-09 : 11:25:04
Ok - I figured it out:

SELECT 'Production' AS Environment,
CASE @@SERVERNAME
WHEN 'SQL01' THEN 'SQL01.HOME.ORG'
END AS [Server],
loginname, sysadmin
FROM syslogins
ORDER BY loginname

Regards

Go to Top of Page
   

- Advertisement -