Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gfaryd
Starting Member
27 Posts |
Posted - 2010-09-08 : 23:39:51
|
| Dear AllSql 2000following is DDL and sample dataCREATE TABLE #tmp(Fname VARCHAR(20),lname varchar (10),Status char(1))goINSERT INTO #tmp VALUES ('John','Terry',null)INSERT INTO #tmp VALUES ('Richard','John',null)INSERT INTO #tmp VALUES ('Kubali','Tony',null)INSERT INTO #tmp VALUES ('Tony','Greig',null)INSERT INTO #tmp VALUES ('Sunny','Shan',null)INSERT INTO #tmp VALUES ('Tony','Mira',null)i want to add status 'A' to first half of the data and Status 'B' to second half of datawhat will be the sql to achieve the task without intoducing any id columnRegards Farid |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2010-09-09 : 00:22:13
|
I dont remember all the limitations of 2000, but I think this will work for you:declare @yak table (v varchar(10))insert into @yakselect 'nathan'union select 'adam' union select 'john' union select 'ann' union select 'jack' union select 'jill'select min(t),vfrom ( select * from (select top 50 percent 'a',* from @yak order by v asc)a(t,v) union all select * from (select top 50 percent 'b',* from @yak order by v desc)b(t,v) )dgroupby v Nathan Skerl |
 |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2010-09-09 : 00:32:15
|
Just realized you want to update in place... try:declare @Status char(1)set @Status='A'update #tmpset @Status=[Status]=case when @Status = 'A' then 'B' else 'A' end Nathan Skerl |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-16 : 13:02:07
|
quote: Originally posted by gfaryd Dear AllSql 2000following is DDL and sample dataCREATE TABLE #tmp(Fname VARCHAR(20),lname varchar (10),Status char(1))goINSERT INTO #tmp VALUES ('John','Terry',null)INSERT INTO #tmp VALUES ('Richard','John',null)INSERT INTO #tmp VALUES ('Kubali','Tony',null)INSERT INTO #tmp VALUES ('Tony','Greig',null)INSERT INTO #tmp VALUES ('Sunny','Shan',null)INSERT INTO #tmp VALUES ('Tony','Mira',null)i want to add status 'A' to first half of the data and Status 'B' to second half of datawhat will be the sql to achieve the task without intoducing any id columnRegards Farid
there's no concept of first and last in sql table unless you specify order in terms of column. how do you want to look for first and last? on basis of what column?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|