Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing stored procedures
Message
 
 
To
07/06/2005 17:04:01
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01021036
Message ID:
01021156
Views:
25
>Sergey,
>
>As always, thanks for your helpful suggestions. I tried using a table variable yesterday and I couldn't get my JOIN syntax but I figured out today. I figured you wouldn't suggest anything uncodable. My problem was that I was trying
>
DECLARE @customerIDTable TABLE (customerID INT)
>
>INSERT @customerIDTable VALUES (1)
>INSERT @customerIDTable VALUES (2)
>INSERT @customerIDTable VALUES (3)
>
>SELECT	@customerIDTable.customerID, a.*
>FROM	@customerIDTable
>	INNER JOIN Address a
>		ON a.customerID = @customerIDTable.customerID
>which doesn't work, but
>
SELECT	c.customerID, a.*
>FROM	Address a
>	INNER JOIN @customerIDTable c
>		ON a.icustid = c.customerID
>works. A bug in the MS SQL parser?
>
>I was disappointed that I couldn't get a JOIN on a TABLE variable to work because I find so few instances in which I can get them to work. Does anyone know if you will be able to INSERT INTO them in MS SQL 2005? What are the advantages of using them over a temp table, anyway, besides not worrying about not dropping them?


Hi David,

Yes, I guess SQL parser gets confused becuase it's local variable on one hand but a table on other. I almost always use 2-3 leters meaningful table aliases when more than one table is involved into select. The longer are table names the more readable it gets with short aliases.

Funny, you asked about Table variables vs temp tables. I talked about it earlier today in Re: Problem with UDF parameters Message #1020831.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform