Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQL case statement

1 view
Skip to first unread message

Excel User

unread,
Nov 9, 2009, 3:15:07 PM11/9/09
to
Hi,

What is wrong with this statement

case when NOT IsNull(firstID) then
(select isnull(username,'not used') from tbl_login
end

I only what to return when is the value of firstID is not Null or empty

Thanks

Erland Sommarskog

unread,
Nov 9, 2009, 5:17:18 PM11/9/09
to
Excel User (eu...@microsoft.com) writes:
> What is wrong with this statement
>
> case when NOT IsNull(firstID) then
> (select isnull(username,'not used') from tbl_login
> end

That is not a statement, but it's an expression. And a syntactically
incorrect one, since a parenthesis is missing after "tbl_login".

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Excel User

unread,
Nov 9, 2009, 6:06:34 PM11/9/09
to
Thanks Erland,

I noticed that as soon as I posted the message, I also forgot to mention
that this is in stored procedure, what can I use to evaluate a value? I also
tried IIF?

Thanks


"Erland Sommarskog" <esq...@sommarskog.se> wrote in message
news:Xns9CBEECE99...@127.0.0.1...

Uri Dimant

unread,
Nov 10, 2009, 1:55:20 AM11/10/09
to
Hi

>I only what to return when is the value of firstID is not Null or >empty

SELECT <columns> FROM tbl WHERE
firstID IS NOT NULL OR firstID =''

"Excel User" <eu...@microsoft.com> wrote in message
news:ebTBOFZY...@TK2MSFTNGP06.phx.gbl...

Excel User

unread,
Nov 10, 2009, 10:35:52 AM11/10/09
to
Uri,

But this is in a stored procedure, not sure what to use here.

Thanks

"Uri Dimant" <ur...@iscar.co.il> wrote in message
news:#RbicKdY...@TK2MSFTNGP02.phx.gbl...

TheSQLGuru

unread,
Nov 10, 2009, 11:12:42 AM11/10/09
to
select isnull(username,'not used')
from tbl_login
where firstID IS NOT NULL


--
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"Excel User" <eu...@microsoft.com> wrote in message

news:us4oFuhY...@TK2MSFTNGP04.phx.gbl...

0 new messages