SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 checking first position for a character
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

20 Posts

Posted - 12/16/2011 :  14:59:32  Show Profile  Reply with Quote
I apologize in advance if this is the wrong place for this question and ask a mod to move it to the appropriate forum.

We recently merged with another company and a former employee wrote some of their website including a function that will check a product code in the database to see if a "W" is anywhere in the code. The problem is it should only be checking the first position. We have other codes that have a "W" elsewhere to indicate a meeting in the western part of the state. Anyone know how to modify the following so it will only check the first letter of the product code?

if instr(ucase(rs("PRODUCT_CODE")), "W") > 0 then

Yak Posting Veteran

55 Posts

Posted - 11/29/2012 :  10:28:26  Show Profile  Reply with Quote
where upper(substring(PRODUCT_CODE,1,1)) = 'W'
Go to Top of Page

Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 11/29/2012 :  10:39:41  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
if ucase(left(rs("PRODUCT_CODE"),1)) = "W"

But you should consider moving this code into a stored procedureso that the database can be restructured if needed.

Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000