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
 Selecting from @Table Variable

Author  Topic 

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-02-09 : 18:34:10
I created a table variable and want to join that table with another "actual" SQL table. However, when i try to select columns from both the table variable and the actual table, the table variable columns don't show up. It appears that my join between the two tables worked and when i select * from my @variable_table everything pulls correctly...

Here's an example of what i'm trying to do:


SELECT

TableA.ColumnX, TableA.ColumnY, TableA.ColumnZ, var.ColumnA, var.ColumnB, var.ColumnC
FROM TableA LEFT JOIN @variable_table var ON TableA.ColumnX = var.ColumnA


I'm just not sure why the variable columns aren't pulling any data. Any help or pointers would be much appreciated!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-09 : 18:35:14
Are you sure your join condition is correct?

Show us some sample data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Coolganny
Starting Member

3 Posts

Posted - 2011-02-10 : 00:36:50
Your query seems to be correct. Can you show some sample data?

Ganesh Ravi
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-02-10 : 01:06:21
Hi,

quote:


SELECT

TableA.ColumnX, TableA.ColumnY, TableA.ColumnZ, var.ColumnA, var.ColumnB, var.ColumnC
FROM TableA LEFT JOIN @variable_table var ON TableA.ColumnX = var.ColumnA


I'm just not sure why the variable columns aren't pulling any data. Any help or pointers would be much appreciated!




your query seems to be correct....

may be reason for
quote:
variable columns aren't pulling any data


there may be no data which supports ON filter condition



--Ranjit
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-10 : 01:27:07
quote:
Originally posted by Brittney10

SELECT

TableA.ColumnX, TableA.ColumnY, TableA.ColumnZ,var.ColumnA, var.ColumnB, var.ColumnC
FROM TableA LEFT JOIN @variable_table var ON TableA.ColumnX = var.ColumnA


I'm just not sure why the variable columns aren't pulling any data. Any help or pointers would be much appreciated!



Seems that the Join Condition is failing (Make sure both columns have same datatypes and data)
Go to Top of Page

Brittney10
Posting Yak Master

154 Posts

Posted - 2011-02-10 : 15:20:40
It appears it was after all and issue with my join.
Go to Top of Page
   

- Advertisement -