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.
Author |
Topic |
rjackman1959
Yak Posting Veteran
60 Posts |
Posted - 2008-12-27 : 16:10:18
|
I am trying to create a view with employee information that will separate the 9 digit zip code into 5 + '-' + 4 and I am getting this error. I'm sure this is an easy fix, but I am new to SQL. Can anyone help me please?Msg 156, Level 15, State 1, Procedure view_name, Line 14Incorrect syntax near the keyword 'else'.ALTER VIEW [dbo].[view_name]ASselect mpp_firstname, mpp_lastname, mpp_address1, mpp_address2, cty_name, cty_state,case when (select (right(mpp_zip, 5))) = (select (left(mpp_zip, 5))) then (select (left(mpp_zip, 5)) as zip_code else left(mpp_zip, 5) + ' - ' + right(mpp_zip, 4) as zip_codeendfrom manpower as m left join city as c on mpp_city = cty_codewhere mpp_terminationdt >= CURRENT_TIMESTAMP |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
rjackman1959
Yak Posting Veteran
60 Posts |
Posted - 2008-12-27 : 18:29:41
|
Thanks, but I took the when out and now I'm getting this error.Msg 156, Level 15, State 1, Procedure wynne_v_drivers_labels, Line 12Incorrect syntax near the keyword 'as'.ALTER VIEW [dbo].[view_name]ASselect mpp_firstname, mpp_lastname,mpp_address1,mpp_address2,cty_name,cty_state,casewhen right(mpp_zip, 5) = left(mpp_zip, 5)then left(mpp_zip, 5 ) as zip_code else left(mpp_zip, 5) + ' - ' + right(mpp_zip, 4) as zip_codeendfrom manpower as m left join city as c on mpp_city = cty_codewhere mpp_terminationdt >= CURRENT_TIMESTAMP |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-12-27 : 20:20:58
|
ALTER VIEW [dbo].[view_name]ASselectmpp_firstname,mpp_lastname,mpp_address1,mpp_address2,cty_name,cty_state,casewhen right(mpp_zip, 5) = left(mpp_zip, 5)then left(mpp_zip, 5 ) as zip_code elseleft(mpp_zip, 5) + ' - ' + right(mpp_zip, 4) as zip_codeend as zip_code from manpower as m left join city as c on mpp_city = cty_codewhere mpp_terminationdt >= CURRENT_TIMESTAMPJIM |
|
|
rjackman1959
Yak Posting Veteran
60 Posts |
Posted - 2008-12-28 : 09:19:22
|
Thank you Jim it's perfect |
|
|
|
|
|
|
|