Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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)) ELSECUSTOMER_NAMEFROM
jbkayne
Posting Yak Master
100 Posts
Posted - 2004-05-27 : 19:09:08
Look up the CASE statement in Books Online.
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))ELSECUSTOMER_NAMEEND AS CustomerNameFROM MyTable
Michael[Edit]I was by 8 seconds! Arg![/Edit]<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
parkerbw2000
Starting Member
4 Posts
Posted - 2004-05-27 : 19:21:52
Thank you, to use to mysql and db2
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>