Syntax in T-SQL

  • Thread starter WWGD
  • Start date
  • #1
WWGD
Science Advisor
Gold Member
5,420
3,685
Hi, I wonder if someone remembers their T-SQL. We have this statement:

upload_2016-4-21_1-52-0.png


Just curious: I remember using SET where SELECT appears. Is this SELECT used in order to
assign values to many variables simultaneously? Also, Is there a reason to use two separate
DECLARE statements , or could we just use a single one?

EDIT : I am also confused about the OBJECT_ID function. I tried it on my SQL Server and got an error message when entering the name of the database I was using, i.e., OBJECT_ID( 'Database Name') generated an error message.
Thanks.
 
Last edited:

Answers and Replies

  • #2
12,477
6,262
From the examples I saw online it seems object-id is used to determine if tables exist not databases so it probably is used to query database metadata like table names, column names and schema names:

https://msdn.microsoft.com/en-us/library/ms187731.aspx

and more on object-id:

http://stackoverflow.com/questions/9372867/what-does-object-id-do-in-sql-server

I think the select is just returning a set of values matching the SELECT criteria. I don't think its making some sort of array of values assigned to the variables mentioned. In standard SQL, you'd use an UPDATE or INSERT with an embedded SELECT to pick rows and columns to be inserted/updated in a separate table.

http://www.w3schools.com/sql/sql_insert_into_select.asp
 
  • Like
Likes WWGD

Related Threads on Syntax in T-SQL

Replies
5
Views
10K
  • Last Post
Replies
2
Views
751
  • Last Post
Replies
11
Views
2K
Replies
1
Views
708
  • Last Post
Replies
2
Views
648
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
20
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
4
Views
3K
Replies
4
Views
1K
Top