Solved

Need JOIN template using SQL Server Templates 2005 / 2008 !

Posted on 2009-04-15
5
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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