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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Like %var1 in stored procedure problem

Author  Topic 

nhamdan
Starting Member

19 Posts

Posted - 2007-06-10 : 05:57:07
Hi All,

I have stored procedure that have a query to select from customer table, and i expect the customer name as parameter, so i want to run the query as this:
select * from customers where cust_name like '%Nas'

But the problem that i cant do it using stored procedure & parameters:

for example i made this but it suppose to return results and its not returning:

DECLARE @SS CHAR(100)
SET @SS = '%Nas'
SELECT * FROM BMS_CUSTOMERS WHERE CUST_NAME_A like @ss


How i can update this to return same results as the first statement??

Thanks all.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-10 : 06:13:55
you are selecting from different table. Is it suppose to be from customers or BMS_CUSTOMERS ?

select * from customers where cust_name like '%Nas'

SELECT * FROM BMS_CUSTOMERS WHERE CUST_NAME_A like @ss



KH

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-06-10 : 06:42:33
If your CUST_NAME column is varchar then it won't work if you declare @SS as CHAR because of the space-padding

Kristen
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-10 : 07:03:33
Good catch


KH

Go to Top of Page

nhamdan
Starting Member

19 Posts

Posted - 2007-06-10 : 07:24:33
Kristen, Thaaaaaaaaaaaaanks alot its working now with your suggestion :).

Thanks for others.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-11 : 09:17:53
<<
How i can update this to return same results as the first statement??
>>

It wont as they are completely different tables

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nhamdan
Starting Member

19 Posts

Posted - 2007-06-11 : 10:30:04
that was a writing mistake ,, ignore it ,, i mean same tables :)
Go to Top of Page
   

- Advertisement -