Author |
Topic |
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 06:56:25
|
What is wrong with this code, because it refuses to stop and continued on until you click Stop?DECLARE @pos int, @curruntLocation char(20), @input varchar(2048)SELECT @pos=0SELECT @input = '1234,2345,3456'SELECT @input = @input + ','WHILE CHARINDEX(',',@input) > 0BEGINSELECT @pos=CHARINDEX(',',@input)SELECT @curruntLocation = RTRIM(SUBSTRING(@input,1,@pos-1))INSERT INTO TABLE_1 (id_uporabnika) VALUES (@curruntLocation)--SELECT @input=SUBSTRING(@input,@pos+1,2048)ENDSELECT * FROM TABLE_1 |
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 07:37:33
|
your while loop is running endlessly because your condition: charindex(',',@input) > 0 is always bigger than zero and it keeps inserting values.you ought to so something with your input or your condition. |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 07:53:21
|
quote: Originally posted by slimt_slimt your while loop is running endlessly because your condition: charindex(',',@input) > 0 is always bigger than zero and it keeps inserting values.you ought to so something with your input or your condition.
thanks.With this code I would like to value: '1234, 2345.3456 "in the same column, write to:TABLE_1:ID_uporabnika:123423453456 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 08:15:28
|
try this:declare @temp table (id_uporabnika varchar(50))declare @input varchar(200) set @input = '1234,2345,3456,12,31415,435'if right(rtrim(@input),1) <> ',' set @input = @input + ','declare @stevc smallintdeclare @del_stringa varchar(50)set @stevc = patindex('%,%',@input)while @stevc <> 0begin set @del_stringa = left(@input, @stevc-1) insert into @temp select @del_stringa set @input = stuff(@input,1,@stevc,'') set @stevc = patindex('%,%',@input)endselect * from @temp |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 08:39:43
|
quote: Originally posted by slimt_slimt try this:declare @temp table (id_uporabnika varchar(50))declare @input varchar(200) set @input = '1234,2345,3456,12,31415,435'if right(rtrim(@input),1) <> ',' set @input = @input + ','declare @stevc smallintdeclare @del_stringa varchar(50)set @stevc = patindex('%,%',@input)while @stevc <> 0begin set @del_stringa = left(@input, @stevc-1) insert into @temp select @del_stringa set @input = stuff(@input,1,@stevc,'') set @stevc = patindex('%,%',@input)endselect * from @temp
thanks worksdeclare @Table_1 table (id_uporabnika varchar(50))declare @input varchar(200) set @input = '1234,2345,3456,12,31415,435'if right(rtrim(@input),1) <> ',' set @input = @input + ','declare @stevc smallintdeclare @del_stringa varchar(50)set @stevc = patindex('%,%',@input)while @stevc <> 0begin set @del_stringa = left(@input, @stevc-1) insert into @Table_1 select @del_stringa set @input = stuff(@input,1,@stevc,'') set @stevc = patindex('%,%',@input)endselect * from @Table_1These data would have liked to have still stored.If you look Table_1 find that this information is not saved.How do I save them forever?Thanks! |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 08:53:59
|
instead of using temporary table (@temp), you should use a normal table. so use this to have your data saved forever.Create table Table_1 (id_uporabnika varchar(50))declare @input varchar(200) set @input = '1234,2345,3456,12,31415,435'if right(rtrim(@input),1) <> ',' set @input = @input + ','declare @stevc smallintdeclare @del_stringa varchar(50)set @stevc = patindex('%,%',@input)while @stevc <> 0begin set @del_stringa = left(@input, @stevc-1) insert into Table_1 select @del_stringa set @input = stuff(@input,1,@stevc,'') set @stevc = patindex('%,%',@input)endselect * from Table_1 |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 09:05:37
|
quote: Originally posted by slimt_slimt instead of using temporary table (@temp), you should use a normal table. so use this to have your data saved forever.Create table Table_1 (id_uporabnika varchar(50))declare @input varchar(200) set @input = '1234,2345,3456,12,31415,435'if right(rtrim(@input),1) <> ',' set @input = @input + ','declare @stevc smallintdeclare @del_stringa varchar(50)set @stevc = patindex('%,%',@input)while @stevc <> 0begin set @del_stringa = left(@input, @stevc-1) insert into Table_1 select @del_stringa set @input = stuff(@input,1,@stevc,'') set @stevc = patindex('%,%',@input)endselect * from Table_1
My mistake.It worked fine, we had to do refresh.Thanks! |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 09:10:10
|
(y) |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 10:53:10
|
quote: Originally posted by slimt_slimt (y)
Ok, this is work.In what way is choose, in any field they go?Eg: How do I set the variable value?id_uporabnika varchar (50)), this is one column.If I have:TextBox1 = 1234TextBox2 = 2345TextBox3 = 3456TextBox4 = 12TextBox5 = 31415TextBox1 = 435Or anything else ...How do I set: @input = '1234, 2345,3456,12,31415,435 'of variables, data will be written to the table?Using Stored procedure.thanks. |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 11:02:06
|
i don't understand what do you want here? |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 11:19:22
|
quote: Originally posted by slimt_slimt i don't understand what do you want here?
If I have only one column in which I get all the information:Example:----- Nickname Empty tableTextBox1: Text = nickname1TextBox2.Text = nickname2TextBox3.Text = nickname3Instead '1234, 2345,3456,12,31415,435 ', I here set the name fieldNickname Tablenickname1nickname2nickname3 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 12:45:51
|
still no clue? sorry. |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2010-08-08 : 13:03:43
|
quote: Originally posted by programer
quote: Originally posted by slimt_slimt i don't understand what do you want here?
If I have only one column in which I get all the information:Example:----- Nickname Empty tableTextBox1: Text = nickname1TextBox2.Text = nickname2TextBox3.Text = nickname3Instead '1234, 2345,3456,12,31415,435 ', I here set the name fieldNickname Tablenickname1nickname2nickname3
They prepared me code in which the values are: '1234, 2345,3456,12,31415,435 'How to replace values: 1234 ...... define its value.TextBox1.Text = programer.So it looks:'programer 2345,3456,12,31415,435' |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-08-08 : 14:06:20
|
Either you solve this issue on VB level (or your programming language level)or you insert this values into a table and load your string/array with each values separately from the table. |
|
|
|
|
|