Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing from a CASE statement to an IF statement

Status
Not open for further replies.

unmlobo

MIS
Apr 11, 2003
64
US
Hello all, I need some help in changing from a CASE statement to an IF statement. Below is the CASE statement that needs changing.

I'm trying to use the SQL Enterprise Manager and it seems to not like CASE statements.

Thanks all!!!


CASE
WHEN [BookLine].[FirstNumber] = [BookLine].[LastNumber] THEN [BookLine].[FirstNumber]
ELSE [BookLine].[FirstNumber] + ' - ' + [BookLine].[LastNumber]
 
you cannot use if inseide a select or insert or update or delete.

Never write any query using Enterprise Manager. In particular do not use Enterprise manager to do any kind of query that affects the data structure or changes the data. ENterprise MAnager does not do these things efficiently and you can lock up your database using Enterpise Manager. Write your queries in Query analyzer instead. But your case syntax is not correct which is at least part of the problem. Look up case in BOL.

"NOTHING is more important in a database than integrity." ESquared
 
Code:
DECLARE @Temp Table (FirstNumber varchar(200), LastNumber varchar(200))
INSERT INTO @Temp VALUES ('12345','67890')
INSERT INTO @Temp VALUES ('12345','12345')
SELECT FirstNumber+ISNULL(NULLIF('-'+FirstNumber,'-'+LastNumber),'')
FROM @Temp

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top