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 2000 Forums
 SQL Server Development (2000)
 Select with an if for sql server 2000

Author  Topic 

parkerbw2000
Starting Member

4 Posts

Posted - 2004-05-27 : 19:06:07
Does anyone have an example of a select statement with an embedded if statement ?

Like:
Select
IF (PATINDEX('%,%',CUSTOMER_NAME)) SUBSTRING(CUSTOMER_NAME,1,PATINDEX('%,%',CUSTOMER_NAME))
ELSE
CUSTOMER_NAME

FROM

jbkayne
Posting Yak Master

100 Posts

Posted - 2004-05-27 : 19:09:08
Look up the CASE statement in Books Online.
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-05-27 : 19:09:16
Yeah

SELECT CASE WHEN PATINDEX('%,%',CUSTOMER_NAME) > 0 THEN SUBSTRING(CUSTOMER_NAME,1,PATINDEX('%,%',CUSTOMER_NAME))
ELSE
CUSTOMER_NAME
END AS CustomerName
FROM MyTable


Michael
[Edit]
I was by 8 seconds! Arg!
[/Edit]
<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

parkerbw2000
Starting Member

4 Posts

Posted - 2004-05-27 : 19:21:52
Thank you, to use to mysql and db2
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-05-27 : 19:25:26
Well, this is a MS SQL Server site, so I'm not sure if that syntax will work with those databases.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page
   

- Advertisement -