Solved

Need JOIN template using SQL Server Templates 2005 / 2008 !

Posted on 2009-04-15
5
195 Views
Last Modified: 2012-05-06
Hi,

I have two tables T1 (X, Y) & T2 (A, B) :

SQL
====

SELECT T1.X, T2.B
FROM T1 JOIN T2
WHERE T1.X = T2.A

TQL
====

SELECT <Columns, sysname, >
FROM <Parent_Table, sysname, > JOIN <Child_Table, sysname, >
WHERE <Parent_Table, sysname, >.<PrimaryKey, sysname, > = <Child_Table, sysname, ).<ForeignKey, sysname, >

Now I want to have the aliases like this:

SQL
====

SELECT T1.X, T2.B
FROM T1 u JOIN T2  v
WHERE u.X = v.A

Can you please provide me the JOIN template using SQL Server Templates 2005 / 2008 ?

TQL
====

-- Need here

Thanks
0
Comment
Question by:milani_lucie
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24150321
Try the following:
SELECT T1.X, 
       T2.B
FROM T1 u 
INNER JOIN T2  v
ON    U.X = V.A

Open in new window

0
 

Author Comment

by:milani_lucie
ID: 24150408
I am expecting TQL. Not an SQL Command.

Thanks
0
 
LVL 25

Accepted Solution

by:
reb73 earned 500 total points
ID: 24150435
Like this, perhaps?
SELECT <Columns, sysname, >
FROM <Parent_Table, sysname, > <Parent_Table_Alias, char(1), > 
JOIN <Child_Table, sysname, > <Child_Table_Alias, char(1), >
WHERE <Parent_Table_Alias, char(1), >.<PrimaryKey, sysname, > = <Child_Table_Alias, char(1), >.<ForeignKey, sysname, >

Open in new window

0
 

Author Comment

by:milani_lucie
ID: 24151268
reb73:

This is what i am looking for. BTW: Where i need to use "sysname" and "Other Data Type (Like Char, Varchar, Int etc..)" ? Can you please explain to me in simple terms ?

Thanks
0
 
LVL 25

Expert Comment

by:reb73
ID: 24151323
The second parameter is the datatype for the parameter value.

sysname is a native datatype used to store/reference object identifiers (like table names, view names, procedure names etc)..

Since your alias is not an object name (and I'm presuming that you would tend to use a 1 char alias), I've used char(1).. But you can change this to a datatype/length that's suitable for you (e.g. char(2), varchar(5) etc)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to extract a "coded date" from a string field? 4 59
Isolation level in SQL server 3 50
How to use TOP 1 in a T-SQL sub-query? 14 45
SQL Query with Sum and Detail rows 2 50
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question