RSS Forums RSS

MSSQL charindex HELP !

Please support our MS SQL advertiser: Programming Forums
Reply
Posts: 1
Reputation: yorks is an unknown quantity at this point 
Solved Threads: 0
yorks yorks is offline Offline
Newbie Poster

MSSQL charindex HELP !

  #1  
Oct 10th, 2008
Hi all

I am pretty new to MSSQL and have a problem. The solution is probably very simple but I cant find it

I have a database field ZIP, I also have string with consists of a number of UK part postcodes eg

'S10 S11 S7 S17 S8 S3 S30'

I want to perform a SELECT check if the database field ZIP is in the string. I have used CHARINDEX as follows

charindex(uzip,'S10 S11 S7 S17 S8 S3 S30') > 0

BUT the problem is if the database field ZIP is , say S1 then it still finds it in the string because S10 in there which is obvioulsy incorrect

any help would be much appreciated

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Posts: 30
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 10
huangzhi huangzhi is offline Offline
Light Poster

Re: MSSQL charindex HELP !

  #2  
Oct 11th, 2008
Change your Select check to:
charindex(' ' + uzip + ' ',' ' + 'S10 S11 S7 S17 S8 S3 S30' + ' ') > 0

This code will check 'S1' <> 'S10'
Hence Wijaya
www.ex-Soft.tk
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the MS SQL Forum
Views: 1043 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:39 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC