943,744 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 2360
  • MS SQL RSS
Oct 10th, 2008
0

MSSQL charindex HELP !

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yorks is offline Offline
1 posts
since Oct 2008
Oct 11th, 2008
0

Re: MSSQL charindex HELP !

Change your Select check to:
charindex(' ' + uzip + ' ',' ' + 'S10 S11 S7 S17 S8 S3 S30' + ' ') > 0

This code will check 'S1' <> 'S10'
Reputation Points: 10
Solved Threads: 13
Light Poster
huangzhi is offline Offline
48 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Transfer values betqween two asp pages
Next Thread in MS SQL Forum Timeline: Query query!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC