Groups | Blog | Home
all groups > sql server mseq > may 2004 >

sql server mseq : SORT QUERY AND VALUE ASSIGNMENT


PARADISE HILLS - FLYING HIGH
5/25/2004 1:21:02 PM
Vishal Parkar
5/26/2004 2:13:45 PM
see following example. it will work in sql server.

--dummy table
create table t(backslashes varchar(50),qtybackslashes int )
--sample records.
insert into t values ('c:\windows',null)
insert into t values ('c:\windows\system',null)
insert into t values ('c:\windows\system\color',null)

--query to get rows in the order of the number of backslashes will be:

select backslashes,
len(backslashes) -len(replace (backslashes, '\','')) as 'no_of_backslashes'
from t
order by 2 desc

--query to update the table with the number of backslashes will be:

update t set qtybackslashes =
len(backslashes) -len(replace (backslashes, '\',''))


--
Vishal Parkar
vgparkar@yahoo.co.in | vgparkar@hotmail.com



AddThis Social Bookmark Button