Hi all,
i have a typical query to divide the data based on column
In tmpdet table for vouchid 101025 refernce column has data more than40 lines as below:
jb 12000 paid
jb 700 paid
jb 700 paid
dhgsdasg
wuwwefwjf
dgfedgfe
dhfeuhfehf
jhfuehfuehf
yfuyruywu
this is a toy
a car
i10 is a car
sdwduwduw
gwyfgwewsch
abcdefeghslds
turkey is a country
golf is a game
dwdwdwyd
gdwgfydfg
qeqewrqw
qwretuturtyir
12123141255
12345678910
movie is cinema
cinema is movie
good movies always refre
banty returns
jaalk is a boy
he is mad
dwydydg
yfwetywuguwior
qydtyqwgdsd
qrwyu is held
joo is hg
mercury hg
maganes metal
aadjdhadasdfj
dyADYDASYDUA
QEATSFADG
qshajshaddadqweqyweqywe
pandas live in antarcitica
dquweqeqwueyuq
now, i have a query as below:
SELECT A.vouchid,
Split.a.value('.', 'VARCHAR(100)') AS String
INTO #temp
FROM (SELECT vouchid,
CAST ('<M>' + REPLACE(isnull(reference,''), char(13) + char(10), '</M><M>') + '</M>' AS XML) AS String
FROM tmpdet) AS A CROSS APPLY String.nodes ('/M') AS Split(a);
select td.vouchid,reference,
--CASE
--WHEN COUNT(String) < 33 THEN '0'
--ELSE '1'
--END IsVoid ,
T.String
--ROW_NUMBER() over(order by reference) RowNumber
From tmpdet td
LEFT JOIN #temp T
ON td.vouchid=T.vouchid
where td.vouchid in (101025,101026,107547)
group by td.vouchid,reference,T.String
order by td.vouchid
drop table #temp
which resulting data as :![]()
here in vouchid column i have 101025,101026,107547 id's and string in reference column is divided based on the lines in reference column.
now, i need another column Is_Void with datatype integer in which result is :
As of now string column is having data divided from refernce column (if reference column forvouchid 101025 has 42 lines of data string column is divided as 42 rows for same vouchid.
now, what i need is if no.of lines in refernce colulmn for single vouchid is greater than 33 lines then Is_Void should be '1',if not '0'. if suppose no.of lines in reference column exceeds 33 lines then Is_void should be '1' for vouchid 101025 and vouchid
101025 should continue for next lines in refernce column (34-42) and should have Is_Void column to be '0'...since (34-42 lines)is < 33 lines.and later next vouchid 101026 should be coming with its refernce colulmn and string division and IS_void result based on no.of lines in reference column. Please help ..i need this in urgent..
thanx in advance..
lucky