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 2005 Forums
 Transact-SQL (2005)
 search function

Author  Topic 

a180884p
Starting Member

3 Posts

Posted - 2008-10-09 : 11:58:58
I have got a query basically to return all the fields from a table, when a person has searched. I have got this query from my manager which does this but do not understand what it does or how it work can any help please:

DECLARE @WSEARCHTEXT nvarchar(50)
SET NOCOUNT ON;
IF @SEARCHTEXT IS NOT NULL AND LEN(@SEARCHTEXT)>0
SET @WSEARCHTEXT = '%'+@SEARCHTEXT+'%'

SELECT lob_LineOfBusinessID,
lob_LineOfBusinessCode,
lob_LineOfBusinessDescription
FROM dbo.LineOfBusiness
WHERE @WSEARCHTEXT IS NULL OR (@WSEARCHTEXT IS NOT NULL AND lob_LineOfBusinessDescription LIKE @WSEARCHTEXT)
ORDER BY lob_LineOfBusinessDescription asc

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-09 : 12:02:10
what is does is return those records from your table having a value in
lob_LineOfBusinessDescription column which contains the pattern user inputed to varaiable @SEARCHTEXT coming in it.
Go to Top of Page
   

- Advertisement -