SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to update column to column through any loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  05:18:41  Show Profile  Reply with Quote
hello all,

i have a table with huge records now i have column id users with

i lakh records and i have age column with 200 records ]

how i can update this 200 records to rest of the users

like

1 mohan 43

2 raju 45

3 kalli 43

4 asha 45

5 jisa 43

6 jaju 45

here example i have 6 records and age 43,45 need to update for all

P.V.P.MOhan

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 01/16/2013 :  05:32:58  Show Profile  Reply with Quote
If you want to update age column ( which is NULL) with a random integer below 200

UPDATE YourTable
SET Age = CAST( RAND()*200 AS INT)
WHERE Age is NULL

--
Chandu
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  05:39:12  Show Profile  Reply with Quote
hi chandu i have some selected ID's in age column like 43,44,45 etc;

now for all users columns this 43,44,45 should be repeated...how i need to do this ???

P.V.P.MOhan
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  06:14:14  Show Profile  Reply with Quote
suggest me i am not able move a bit

P.V.P.MOhan
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 01/16/2013 :  07:35:03  Show Profile  Reply with Quote
hey guys i am waiting for any suggestion??? help me out

P.V.P.MOhan
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 01/16/2013 :  07:38:31  Show Profile  Reply with Quote
quote:
Originally posted by mohan123

hey guys i am waiting for any suggestion??? help me out
P.V.P.MOhan

Why you need that requirement?
provide expected output for us...

--
Chandu
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 01/16/2013 :  07:52:16  Show Profile  Reply with Quote
This is not exact ur requirement:

Execute once...

declare @t tABLE( id int, users varchar(10),  age int)
insert into @t 
SELECT 1, 'mohan', 40 union all
SELECT 2, 'raju' ,null union all
SELECT 3, 'kalli', 43 union all
SELECT 4, 'asha', null union all
SELECT 5, 'jisa', 43 union all
SELECT 6, 'jaju', null  union all
SELECT 7, 'jazxdfju', 45 union all
SELECT 8, 'jaju', null union all
SELECT 9, 'kagvewlli', 43 union all
SELECT 10, 'abxvsha', null union all
SELECT 11, 'vgsfsa', 40

;with cte AS (SELECT distinct id, age FROM @t WHERE age is NOT NULL)
UPDATE @t 
SET age = c.age
FROM @t t1 
cross apply (SELECT top 1 age FROM cte WHERE id >= t1.id ) c
where t1.age is null

SELECT * FROM @t


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000