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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql help req

Author  Topic 

gfaryd
Starting Member

27 Posts

Posted - 2010-09-08 : 23:39:51


Dear All

Sql 2000

following is DDL and sample data

CREATE TABLE #tmp

(

Fname VARCHAR(20),
lname varchar (10),
Status char(1)

)
go

INSERT 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 data

what will be the sql to achieve the task without intoducing any id column

Regards




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 @yak
select 'nathan'union select 'adam' union select 'john' union select 'ann' union select 'jack' union select 'jill'

select min(t),v
from ( 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)
)d
group
by v


Nathan Skerl
Go to Top of Page

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 #tmp
set @Status=[Status]=case when @Status = 'A' then 'B' else 'A' end



Nathan Skerl
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-16 : 13:02:07
quote:
Originally posted by gfaryd



Dear All

Sql 2000

following is DDL and sample data

CREATE TABLE #tmp

(

Fname VARCHAR(20),
lname varchar (10),
Status char(1)

)
go

INSERT 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 data

what will be the sql to achieve the task without intoducing any id column

Regards




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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -