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 |
AdamWest
Constraint Violating Yak Guru
360 Posts |
Posted - 2014-02-20 : 17:40:04
|
HI I have a PURCHASE ORDER NUMBER which is character24 pos. and I only want to select in the query those which start with '101' from 1 to 3 = '101'how to do this in the querry? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-02-20 : 18:10:45
|
where left(yourcolumn1, 3) = '101'Hopefully your table isn't very big as this is a performance concern.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
maunishq
Yak Posting Veteran
71 Posts |
Posted - 2014-02-21 : 14:17:33
|
SUBSTRING(column_name,1,3)='101'If possible, try to use SUBSTRING function for such selections.!!_(M)_!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-02-21 : 14:31:13
|
And why oh why would you advise SUBSTRING over LEFT in this situation, maunishq? They achieve equivalent results for the left characters. LEFT saves some typing. Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
maunishq
Yak Posting Veteran
71 Posts |
Posted - 2014-02-24 : 12:07:41
|
Yes, They both perform similar. Opt for any of them. !!_(M)_!! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-02-24 : 13:14:19
|
WHERE Col1 LIKE '101%'will use an index if present. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|