Question:
Use SQL JOIN in SQL Server or in code?
SweetCheeks
2009-02-12 13:02:00 UTC
I'm trying to join two tables together in SQL server for updating/inserting/etc and can't figure out if you can join tables inside SQL Server or if you have to do it in the code when you are communiciating with the database. Is it possible to permanently join two tables in SQL Server? If so, how?

Thanks much! ^_^
Three answers:
kevin c
2009-02-12 13:08:24 UTC
Are you trying to do something like this:



UPDATE (tblA INNER JOIN tblB ON tblA.x = tblB.x)

SET tblA.y = tblB.y



OR:



INSERT INTO TABLE tblA (y)

VALUES SELECT y

FROM tblB INNER JOIN tblA ON tblA.x = tblB.x



You can do it in your code, or you can write a stored procedure to do it-



a stored procedure will be WAY FASTER than doing a remote ODBC connect, and all you'd do is just invoke the stored procedure, because everything is running on the server (the more you can get to run on the server the better).



It gets trickier with paramerterized procedures, though, but it's doable in either Perl or VB, but other languages may not have "native" drivers.



HTH
TechBuddy
2009-02-12 13:08:49 UTC
No, you can't permanently join two tables together, and I'm not sure why you'd want to do that.



You'll want to join your table in the UPDATE statement so that you can reference fields from both tables.



See the following site for some help on transact SQL update statements:

http://msdn.microsoft.com/en-us/library/ms177523.aspx
John Michael
2009-02-12 13:06:04 UTC
"Is it possible to permanently join two tables in SQL Server"



No, you'll need to do it in the code. Tables are dumb, they don't know how one table relates to another. You give them relationships by making joins and other calls from your server side scripting language of choice.



JMK

http://realjobdescriptions.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...