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
 table variable alternate
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pnpsql
Posting Yak Master

India
241 Posts

Posted - 05/09/2012 :  00:27:24  Show Profile  Reply with Quote
hi team , i have a table abc1 that have 6 cols id , a1 , a2 , a3, a4, a5
i need insert values of these columns in a table vaiable and the
traverse the values. can it be done by any other way like cte.

ex:

DECLARE @var1 TABLE (
a1 VARCHAR(100) identity,
a2 VARCHAR(100));

then

insert into @var1 (a1)
select a1 from abc1 where ID = 1

insert into @var1 (a2)
select a1 from abc1 where ID = 1

insert into @var1 (a3)
select a1 from abc1 where ID = 1

insert into @var1 (a4)
select a1 from abc1 where ID = 1

insert into @var1 (a5)
select a1 from abc1 where ID = 1

please suggest the better way

challenge everything

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 05/09/2012 :  06:47:25  Show Profile  Reply with Quote
what are you trying to do not clear. In your code you have specified the IDentity on varchar datatype that does not allow .. indentiy can be set on numeric data.Is your code working? I dont think so it would be working ..For inserting the data see the below example.




DECLARE @var1 TABLE (
a1 int identity,
a2 VARCHAR(100));


insert into @var1 (a2)values('2');

select * from  @var1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 05/09/2012 :  16:07:14  Show Profile  Reply with Quote
also you dont need seperate inserts for inserting column values. you can simply do them in a single statement


insert into @var1 (a1,a2,...a6)
select a1,a2,...,a6 from abc1 where ID = 1 


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.09 seconds. Powered By: Snitz Forums 2000