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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Parsing vchar string for value BEGINS <string>

Author  Topic 

pwvailla
Starting Member

31 Posts

Posted - 2010-11-19 : 14:04:03
Hi,

What would you use to check if a field, MRP_PLANNER, begins with the values (GG1, GG2, GG3, R71, R72, R73, TP1, TP2, TP3)?

Is there a SELECT IF mrp_planner BEGINS WITH ('GG1', 'GG2', 'R70', 'R71', 'TP1', 'TP2') SQL statement? As opposed to the LIKE or CONTAINS constructs... or do you have to wrap a substring on the first 4 characters, then use CONTAINS?

Thanks again

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-11-19 : 14:40:12
IF left(mrp_planner,3) in ('GG1', 'GG2', 'R70', 'R71', 'TP1', 'TP2')

==========================================
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-21 : 03:49:28
you can also do

SELECT t.*
FROM Yourtable t
INNER JOIN (SELECT 'GG1' AS Val UNION ALL
SELECT 'GG2' UNION ALL
SELECT 'GG3' UNION ALL
SELECT 'R71' UNION ALL
SELECT 'R72' UNION ALL
SELECT 'R73' UNION ALL
SELECT 'TP1' UNION ALL
SELECT 'TP2' UNION ALL
SELECT 'TP3'
)t1
ON t.MRP_PLANNER LIKE t1.Val + '%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -