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
 SQL Server Development (2000)
 Stored Procedure SQL syntax problem

Author  Topic 

Keats
Starting Member

1 Post

Posted - 2003-06-30 : 05:59:26
Hey everyone!

Im working with VB.net in correlation with MS SQL server and im trying to write a function that matches strings with their counterpart in the database. I do this by using a stored procedure that i call from my VB code. The stored procedure looks like this:
CREATE PROCEDURE SpecYrkesKod_GetList
(@fbdnr [numeric],
@avtnr [numeric],
@namn [nvarchar])
AS
SELECT dbo.lr_yrke.yrkkod, dbo.lr_yrke.yrktext
FROM dbo.lr_yrke
WHERE (fbdnr = @fbdnr)
AND (avtnr = @avtnr)
AND yrktext LIKE '%' + @namn + '%'
GO

with the intended usage that it should find any string in the DB that contains the characters stored in the namn-variable. However, this syntax returns way to many rows, all of which are not matching. For example if i use the syntax :
....AND yrktext = @namn + '%'

it manages to find any string starting with the characters in the namn-variable. However, if I use the following:

....AND yrktext = '%' + @namn
it fails again and return completely irrelevant results.

Does anyone know why this is, and how I should write it so that it works ?

Thanks
/joakim



Edited by - merkin on 06/30/2003 07:02:14

atatham
Starting Member

4 Posts

Posted - 2003-06-30 : 07:22:16
Does replacing like with = make any difference.

Go to Top of Page

Amethystium
Aged Yak Warrior

701 Posts

Posted - 2003-06-30 : 07:28:13
What you have done is perfectly fine. I would check your data to be honest.

No reason why it shouldn't work.


Go to Top of Page
   

- Advertisement -