yurps (yurps (AT) yahoo (DOT) co.uk) writes:
Quote:
Hi I have a weird problem I want to cursor thru the values in a
temporary table and use the values to do a select statement to insert
into another temporary table...This select statement uses a like clause
something like where....when I take off the insert still nothing comes
back from the select...when I hardcode values it works...I get
results...is there something wrong with appending a +'%' to a value
read from a cursor??? |
I would guess that there are trailing spaces. Rewrite as:
DECLARE @DEPT VARCHAR(65)
SET @DEPT = "00201,00203"
DECLARE @TB_ABSENCES TABLE(DeptOrEmpId VARCHAR(65))
INSERT INTO @TB_ABSENCES TABLE
SELECT Code
from TB_EMPLOYEE_DEPARTMENT T2
JOIN [ISIS].[dbo].[FU_GET_DEPTS_FROM_STRING](',', @DEPT) D
ON T2.V_HIERARCHY_CODE LIKE rtrim(V_DEPT) + '%'
Yeah, that's right. No cursor. There is no need for it, and it could
be costly in terms of performance.
--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp