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 2005 Forums
 Transact-SQL (2005)
 Basic sub query help

Author  Topic 

stev1ef
Starting Member

3 Posts

Posted - 2010-09-07 : 11:22:47
Hi, I want to write a select subquery.

Basically if I have a list of fields I am calling, i.e.

select
u.user, ua.ip,u.log... etc
from user u join useraccess ua etc.

I want to write an subquery that will return nothing, i.e. ‘’, or if the u.loginname value is like ‘ut%’ then what is in the field u.loginname

I’ve tried writing if/else statements, case statements and creating a variable but I can’t get it to work?

Any help would be appreciated??

If anyone needs more info to help me out Let me know and I'll gladly provide.

Thanks
Steve

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-07 : 12:06:50
select
u.user,
case
when u.loginname like 'ut%' then u.loginname
else ''
end as loginname,
ua.ip,
...
from ...



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -