September 29, 2005 at 5:25 am
how to separate sentence "Eko Indriyawan Lagi Makan" into four field become like this :
field1 -->> "Eko"
field1 -->> "Indriyawan"
field1 -->> "Lagi"
field1 -->> "Makan"
and "Eko Indriyawan Lagi Makan" can be changed with another sentence, for example like this "Aku suka cewek itu", so we can extract it into
field1 -->> "Aku"
field1 -->> "suka"
field1 -->> "cewek"
field1 -->> "itu"
so the sentence can be changed anytime or we can say, that it sentence is dynamic......
thanxs for a person who can help me........
September 29, 2005 at 9:26 am
A bit slapped together, but will work for you.
declare @thestring as varchar(100)
declare @i as int
declare @goback as int
declare @counter as int
set @thestring = 'sasas fdfdfewew wwrwewr'
set @i = 1
set @counter = 0
set @goback = 1
while @i < len(@thestring)+1
begin
set @counter = @counter + 1
If substring(@thestring,@i,1) = ' ' or @i = len(@thestring)
begin
print substring(@thestring,@goback,@counter)
set @goback = @i+1
set @counter = 0
end
set @i = @i + 1
end
September 30, 2005 at 9:08 am
Another way to do it:
CREATE TABLE #yourtable(field1 varchar(100))
DECLARE @input_string varchar(200)
DECLARE @parse_string varchar(200)
SET @input_string = ' Eko Indriyawan Lagi Makan '
/*strip leading and trailing spaces*/
SET @parse_string = LTRIM(RTRIM(@input_string))
/*if there are any spaces, take the part before first space*/
WHILE CHARINDEX(' ',@parse_string) <> 0
BEGIN
INSERT INTO #yourtable (field1) SELECT LEFT(@parse_string, CHARINDEX(' ',@parse_string)-1)
SET @parse_string = LTRIM(RIGHT(@parse_string, LEN(@parse_string)- CHARINDEX(' ',@parse_string)))
END
/*now insert the rest, if any*/
IF LEN(@parse_string)>0
BEGIN
INSERT INTO #yourtable (field1) SELECT @parse_string
END
SELECT * FROM #yourtable
Supposing you use space as a delimiter, and that if there are several spaces in a row, you treat them as one space... and also ignoring any leading or trailing spaces. That's how I understood the question - you don't want to insert any rows with NULL values or just spaces, do you? If you wish to use another delimiter, it is easy to modify the SQL and add a @delimiter VARCHAR(1) parameter... but then you'd have replace LTRIM and RTRIM with other manipulations (unless you are sure that all the data will be in good shape, which is rather rare).
September 30, 2005 at 10:32 am
thanx for your answer...
October 3, 2005 at 1:27 am
I'll be glad to assist you with locking, but what precisely is the problem?
Generally, SQL Server decides for every query what type of locking is best - rows, pages or entire table. You can change this by using hints for every table (or just some of them) in the query, or by setting isolation level which affects the entire query. However, you have to be careful and know what you are doing - read the "Isolation levels" and "Locking hints" and "Understanding and avoiding blocking" topics in BOL.
If you still have some questions, just ask - but I need to know more about the problem to look for an answer.
HTH, Vladan
October 3, 2005 at 6:15 am
thanxs..........
but i still confuse with yout explanation, i can't accept you idea clearly. Can you describe it by example that explain "locking".
i'm so sorry........
thank you very much for Vladan
sorry i disturb your time......
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply