| |

VerySource

 Forgot password?
 Register
Search
View: 932|Reply: 4

May I define a table variable, how to write the result set to a table variable is as follows

[Copy link]

4

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-6 09:00:01
| Show all posts |Read mode
declare @ table1 table (nvarchar (20), nvarchar (20))


select * into @ table1 from (select * from .......)

The formula above doesn't work

thanks
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-3-25 05:45:01
| Show all posts
declare @ table1 table (a nvarchar (20), b nvarchar (20))


insert into @ table1 select * from (select * from .......) a
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-3-25 08:15:02
| Show all posts
declare @mytable table
(
id int,
name varchar (10)
)

insert into @mytable (id, name)
select 1, 'Zhang San'

select * from @mytable

--result
1 sheet three
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-3-26 12:30:01
| Show all posts
--try

declare @ table1 table (col1 nvarchar (20), col2 nvarchar (20))

insert @ table1 select col1, col2 from tbName
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-3 22:45:01
| Show all posts
declare @ table1 table (col1 nvarchar (20), col2 nvarchar (20))
insert into @ table1 (col1, col2) select col1, col2 from tbName
or
insert into @ table1 select col1, col2 from tbName

Writing table variable data is best written column names
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list