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 |
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-09-20 : 03:09:16
|
Hi All,I want to get the list of names starting with a particular letter.this letter should be passed as parameter in the query. I have used the following query,Select Cust_Code,Cust_Name,Cust_Add1 + Cust_Add2 as Address From Customer Where Cust_Code Like @Cust_Code Order By Cust_Name ASCI am not sure whether the above query is correct.Any help is appreciated. |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2013-09-20 : 03:27:59
|
Select Cust_Code,Cust_Name,Cust_Add1 + Cust_Add2 as Address From Customer Where Cust_Code Like @Cust_Code+'%' Order By Cust_Name ASC |
 |
|
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-09-20 : 03:38:36
|
That was the confusion actually for me,how to use '%' in the query.now resolved.Thank you for your help. |
 |
|
sigmas
Posting Yak Master
172 Posts |
Posted - 2013-09-20 : 06:04:57
|
You also can use CHARINDEX like thisSelect Cust_Code,Cust_Name,Cust_Add1 + Cust_Add2 as Address From Customer Where charindex(@Cust_Code,Cust_Code)=1 Order By Cust_Name |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-09-20 : 07:00:46
|
also possible: where left(cust_code,1) = @Cust_Code Too old to Rock'n'Roll too young to die. |
 |
|
|
|
|