Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String manipulation
Message
From
04/04/2002 06:07:01
 
 
To
03/04/2002 23:39:27
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
General information
Forum:
Visual Basic
Category:
SQL Server
Miscellaneous
Thread ID:
00640706
Message ID:
00640763
Views:
23
This message has been marked as the solution to the initial question of the thread.
Try this (changes with your old code are between --/// and -\\\):

CREATE TABLE #testtable (var1 varchar(8000))
DECLARE @str varchar(50)
DECLARE @sql varchar(8000)
DECLARE @tbl sysname
DECLARE @custname varchar(8000)


DECLARE
@b numeric,
@pos int,
@x int,
@list varchar(8000),
@newstr varchar(8000),
@newpos int,
@lenofstring int,
@count int

SET @custname = 'Art,Creative Kitchens'
SET @list = @custname
--///
--SET @x = 1
SET @x = 0
--\\\
Set @lenofstring = len(@list)
Set @count =0
--///
--SET @pos = charindex(',',@list,@x)
SET @pos = charindex(',',@list)
--\\\

WHILE @pos > 0
BEGIN
Set @count=@count+1

--///
--Set @str = substring(@list,@x,@pos-@x)
Set @str = substring(@list,@x+1,@pos-@x-1)
--\\\
Set @x = @pos

-- THIS LINE IS MESSED UP
-- This line are correct!!!
Set @newstr = substring(@list,@x+1,@lenofstring)

--///
--Set @pos = charindex(',',@newstr,@x)
Set @pos = charindex(',',@list,@x+1)
--\\\

--??? You do not need this
--if @count >=1
--BEGIN
--???

--///New
IF @x > 0
BEGIN
INSERT INTO #testtable SELECT customer.customername
FROM customer INNER JOIN orderdetails ON
customer.customerid = orderdetails.customerid
WHERE customer.customername = @str
print @str
END
--\\\End New

--??? You do not need this
--END
--ELSE
--BEGIN
--INSERT INTO #testtable SELECT customer.customername
--FROM customer INNER JOIN orderdetails ON
--customer.customerid = orderdetails.customerid
--WHERE customer.customername = @newstr
--print @newstr
--END
--???

if @pos <= 0
BEGIN
--///
--Set @str = substring(@list,@x,len(@list))
Set @str = substring(@list,@x+1,len(@list))
--\\\
INSERT INTO #testtable
SELECT customer.customername
FROM customer INNER JOIN orderdetails ON
customer.customerid = orderdetails.customerid
WHERE customer.customername = @str
print @str
END
END
SELECT * FROM #testtable

Plamen Ivanov
MCSD .NET Early Achiever and MCAD .NET Charter Member (VB .NET/SQL Server 2000)
MCSD (VB 6.0/SQL Server 2000)

VB (.NET) - what other language do you need in the whole Universe?...

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform