table-variable Questions

2

Solved

How can I use query result stored into a record type variable for another query within the same stored function? I use Postgres 9.4.4. With a table like this: create table test (id int, tags text...
Centenarian asked 1/12, 2015 at 11:57

3

Solved

I have a small stored procedure below. I am taking the table name as an input parameter to the stored procedure so that I'm planning to insert the data into the temp table and display the same. T...
Resound asked 28/2, 2014 at 20:24

13

Solved

In SQL Server 2005, we can create similar tables in two different ways. We can use a table variable: declare @tmp table (Col1 int, Col2 int); Or we can use a temporary table: create table #tmp (Co...
Tracay asked 26/8, 2008 at 12:27

8

Solved

I have a table variable in a script (not a stored procedure). Two questions: How do I drop the table variable? Drop Table @varName gives an "Incorrect snytax" error. Should I always do this? I he...
Meshed asked 13/4, 2011 at 18:0

11

Solved

Is there anyway to loop through a table variable in T-SQL? DECLARE @table1 TABLE ( col1 int ) INSERT into @table1 SELECT col1 FROM table2 I use cursors as well, but cursors seem less flexible t...
Chalutz asked 16/10, 2009 at 13:54

4

Solved

I would like to debug a complex T-SQL script using SSMS 2012. I can run the script in debug mode and place breakpoints, as well as step through my script, but I can't see the values stored in my ...
Defluxion asked 12/7, 2013 at 8:12

8

Solved

I am trying to achieve: declare @TEMP table (ID int, Name varchar(max)) insert into @temp SELECT ID, Name FROM Table SELECT * FROM @TEMP WHERE @TEMP.ID = 1 <--- ERROR AT @TEMP.ID But I'm ge...
Iodide asked 1/8, 2013 at 13:23

9

Solved

Can we see the values (rows and cells) in a table valued variable in SQL Server Management Studio (SSMS) during debug time? If yes, how?
Feckless asked 14/12, 2009 at 13:14

3

Solved

Can you create an index on a table variable in SQL Server 2000? i.e. DECLARE @TEMPTABLE TABLE ( [ID] [int] NOT NULL PRIMARY KEY ,[Name] [nvarchar] (255) COLLATE DATABASE_DEFAULT NULL ) Can ...
Tetratomic asked 20/5, 2009 at 3:46

2

Solved

I can declare a table variable as such: DECLARE @tv_source TABLE(c1 int, providerName varchar(50), providerSMS varchar(50)) If I then execute the following, I see the table name similar to: "#4...
Comte asked 16/1, 2013 at 22:50

8

Solved

Got a complex SELECT query, from which I would like to insert all rows into a table variable, but T-SQL doesn't allow it. Along the same lines, you cannot use a table variable with SELECT INTO o...
Allisan asked 1/10, 2010 at 10:12

6

Solved

I'm learning more details in table variable. It says that temp tables are always on disk, and table variables are in memory, that is to say, the performance of table variable is better than temp ta...
Fertilizer asked 8/8, 2012 at 4:46

4

Solved

I am wondering why the table variables inside while loop does not behave like other variables. Table variables created only once and will be used across through out whole looping. but other variabl...
Romanov asked 20/9, 2010 at 11:41

3

i have lately been using dapper and all in all had no problems with it except when using table variables. For demonstration, I use a modified example from this thread. This code works without pro...
Daubigny asked 11/1, 2014 at 9:30

5

Solved

I have the following TSQL table variable: declare @NumDaysMonth table ( month_id smallint, num_days smallint ) I just want a quick look-up for the number of days in each month. How can I initi...
Gorget asked 25/9, 2012 at 18:48

1

Solved

What I actually want to do is I want to send a string array to SQL Server. I am using SQL Server 2008. This can be marked as duplicate but I am facing a whole other problem when implementing a sol...
Piotrowski asked 29/2, 2016 at 13:0

1

I have a SELECT query on a view, that contains 500.000+ rows. Let's keep it simple: SELECT * FROM dbo.Document WHERE MemberID = 578310 The query runs fast, ~0s Let's rewrite it to work with the...
Euxenite asked 26/1, 2016 at 9:21

1

Solved

Can any one please tell me where to use CTE, temp table and table variable? I read about their differences but i'm confused with their usage. please help. Thanks.

3

Are table variables created in memory or in tempdb? Same for short temp tables?
Youmans asked 18/8, 2010 at 13:18

5

Solved

I have a T-SQL table variable (not a table) which has an auto incrementing identity column. I want to clear all data from this variable and reset the identity column value to 1. How can this be don...
Offbeat asked 29/9, 2008 at 1:34

1

I have the following table variable declaration: DECLARE @MyTable TABLE ( --ten columns declared here ) and I want to declare another table variable with identical structure (so that I insert-f...
Suttles asked 18/12, 2013 at 12:56

3

Solved

CTE (Common Table Expression) vs Temp tables or Table variables, which is faster?

2

Solved

Why are temporary tables faster than table variables for joins in SQL Server? NOTE: In both scenarios the tables have PK, and the tables are joined with other "physical" tables through the PK.
Eb asked 12/7, 2013 at 17:21

7

Solved

I have problems with SQL performance. For sudden reason the following queries are very slow: I have two lists which contains Id's of a certain table. I need to delete all records from the first li...
Honeysuckle asked 23/5, 2013 at 12:59

2

Solved

I am currently using SQL Server 2008, and I am trying to create a statement using a table variable to insert multiple rows into the table. As it stands right now, I have to insert the information b...
Tetherball asked 14/1, 2013 at 17:8

© 2022 - 2024 — McMap. All rights reserved.