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 |
|
hurdy
Starting Member
17 Posts |
Posted - 2010-03-02 : 20:02:54
|
| Hi all,Thank you for your time out to read this post.Is there a SQL statement that I can use to return items from a database table where the search parameter is the first 6 characters of a database column?For example, I have 1 table with 3 colums.Column1 data:1, 2, 3Column2 data: (this column is in the string datatype, not int)101111741 *note - 9 characters long101222852101333963Column3 data:RobJohnSteveI need an SQL statement similar to the follow;SELECT Column1, Column3FROM TableWHERE Column2=@Column2 -- but I want to be able to search by the first 6 characters as they are always unique. Please note column2 is in the string format.So, if I search using 101222 it should return - 2, John.Thank you for your time and all advice is greatly appreciated.Rob |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-03-03 : 00:15:44
|
| SELECT Column1, Column3FROM TableWHERE left(column2,6)=@Column2Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-03 : 01:15:29
|
| Better approach for index usageSELECT Column1, Column3FROM TableWHERE column2 like @Column2+'%'MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|