join for three tables and concatenate two columnshttp://forums.asp.net/t/1793454.aspx/1?join+for+three+tables+and+concatenate+two+columnsTue, 17 Apr 2012 10:53:20 -040017934544935161http://forums.asp.net/p/1793454/4935161.aspx/1?join+for+three+tables+and+concatenate+two+columnsjoin for three tables and concatenate two columns <p>Table1: 'tbl_partnerhirerege'<br> columns: seskey(pk) &nbsp; &nbsp;compannyname &nbsp; shortname &nbsp; &nbsp;address &nbsp; &nbsp; &nbsp; country &nbsp; &nbsp; customer<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IBM PVTLMTD &nbsp; &nbsp; &nbsp; &nbsp;IBM &nbsp; &nbsp; &nbsp; &nbsp;BANGALORE &nbsp; &nbsp; INDIA &nbsp; &nbsp; &nbsp; IBMINDIA<br> Table2: 'tbl_quotation'<br> columns: seskey(pk) cutomer_id(fk) quotation_id(fk) &nbsp; rate &nbsp; &nbsp; no_of_test &nbsp; &nbsp; amount<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 100<br> Table3: 'tbl_quotation_master'<br> columns: seskey(pk) &nbsp; cutomer_id(fk) &nbsp; &nbsp;quotation_date <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IBM16042012</p> <p>Above are my three tables. Now i should join above three tables based on quotaion_id. And from table1 shortname column and from table3 quotation_date column should be concatenate.</p> <p>Anybody please tell me. Its very urgent. I am waitning for your reply.<br> Thank you</p> 2012-04-16T16:58:39-04:004935173http://forums.asp.net/p/1793454/4935173.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>on the basis of which column you want to join tables</p> <p>and you are having problem in joining or concatenation</p> 2012-04-16T17:05:02-04:004935177http://forums.asp.net/p/1793454/4935177.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>customer_id base</p> 2012-04-16T17:06:50-04:004935185http://forums.asp.net/p/1793454/4935185.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>SELECT *, shortname&#43;' '&#43;quotation_date FROM tbl_partnerhirerege t1</p> <p>INNER JOIN tbl_quotation t2 ON t1.seskey=t2.cutomer_id</p> <p>INNER JOIN tbl_quotation_master t3 ON t2.quotation_id=t3.seskey</p> 2012-04-16T17:10:57-04:004935191http://forums.asp.net/p/1793454/4935191.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>i am considering first table is having customer_id</p> <p>select t1.shortname&#43;' '&#43;t3.quotation_date&nbsp;from&nbsp;&nbsp;tbl_partnerhirerege t1 join tbl_quotation t2 on t1.customer_id=t2.customer_id</p> <p>join tbl_quotation_master t3 on t2.customer_id=t3.customer_id</p> <p>&nbsp;</p> <p>let me know the result</p> <p>&nbsp;</p> 2012-04-16T17:14:54-04:004935202http://forums.asp.net/p/1793454/4935202.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>Hi,</p> <p>From the table structure it is clear that table2 and table3 are related with customer id&nbsp;</p> <p>but what is the relation of &nbsp;table1 &nbsp;with table2 and table3 which is the column you can join</p> 2012-04-16T17:21:47-04:004935215http://forums.asp.net/p/1793454/4935215.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>HI</p> <p>i am getting error when i execute @company=4</p> <p>Msg 245, Level 16, State 1, Procedure SP_QUOTATION_JOIN, Line 14<br> Conversion failed when converting the varchar value 'IBMINDIA' to data type int.</p> <p></p> 2012-04-16T17:31:52-04:004935218http://forums.asp.net/p/1793454/4935218.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>from table1 customer_id is 'BMINDIA' and &nbsp;from table2 &nbsp;customer_id 2 &nbsp; and from table3 customer_id 2&nbsp;</p> 2012-04-16T17:34:40-04:004935221http://forums.asp.net/p/1793454/4935221.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>Hi,</p> <p>What is the datatype of table2 customerid and table3 customerid if it is numeric then&nbsp;</p> <p>You cannot join varchar column to numeric column ,</p> <p>so if it contains IBMINDIA and 1 it will give error for conversion</p> <p>So, the solution is you have <strong>to make customerid of table3 and table3 to the same datatype as table1.customerid or varchar</strong></p> <p></p> 2012-04-16T17:38:47-04:004935247http://forums.asp.net/p/1793454/4935247.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>select t1.shortname&#43;' '&#43;t3.quotation_date&nbsp;from&nbsp;&nbsp;tbl_partnerhirerege t1 join tbl_quotation t2 on t1.BMINDIA=t2.customer_id</p> <p>join tbl_quotation_master t3 on t2.customer_id=t3.customer_id</p> 2012-04-16T17:57:48-04:004935339http://forums.asp.net/p/1793454/4935339.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>hi,</p> <p>i changed into customerid as int datatype in table1. And my code is&nbsp;</p> <p></p> <p>ALTER procedure [dbo].[SP_QUOTATION_JOIN]<br> @company INT<br> as<br> --SELECT *, shortname&#43;' '&#43;quotation_date FROM tbl_partnerhirerege t1</p> <p>--INNER JOIN tbl_quotation t2 ON t1.userdid=t2.userdid</p> <p>--INNER JOIN tbl_quotation_master t3 ON t2.userdid=t3.userdid</p> <p></p> <p>but when i execute i am getting all userdid records</p> <p>Actually if i will give @company=5</p> <p>Then that particular record will be diplay based on that userdid. but iam getting all records. can you tell me what is the problem</p> <p></p> 2012-04-16T19:20:08-04:004935694http://forums.asp.net/p/1793454/4935694.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>Is this your table structure?</p> <p>Table1: 'tbl_partnerhirerege'<br> columns: seskey(pk)&nbsp;&nbsp;&nbsp; compannyname&nbsp;&nbsp; shortname&nbsp;&nbsp;&nbsp; address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; country&nbsp;&nbsp;&nbsp;&nbsp; customer<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBM PVTLMTD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BANGALORE&nbsp;&nbsp;&nbsp;&nbsp; INDIA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBMINDIA<br> Table2: 'tbl_quotation'<br> columns: seskey(pk) cutomer_id(fk) quotation_id(fk)&nbsp;&nbsp; rate&nbsp;&nbsp;&nbsp;&nbsp; no_of_test&nbsp;&nbsp;&nbsp;&nbsp; amount<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 100<br> Table3: 'tbl_quotation_master'<br> columns: seskey(pk)&nbsp;&nbsp; cutomer_id(fk)&nbsp;&nbsp;&nbsp; quotation_date<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBM16042012</p> <p></p> <p>From your table structure, table2 and table3 are related, both have customer_id but don't have a relation to table1. In you stored procedure you are using user_id. From where did it comes from? In your tables, there is no user_id column.</p> 2012-04-17T03:36:46-04:004935729http://forums.asp.net/p/1793454/4935729.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>Hi,</p> <p><strong>As per your first post you have following table structure</strong></p> <p>Table1: 'tbl_partnerhirerege' columns:</p> <p>seskey(pk)&nbsp;&nbsp;&nbsp; compannyname&nbsp;&nbsp; shortname&nbsp;&nbsp;&nbsp; address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; country&nbsp;&nbsp;&nbsp;&nbsp; customer &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p> <p>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBM PVTLMTD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BANGALORE&nbsp;&nbsp;&nbsp;&nbsp; INDIA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBMINDIA</p> <p>&nbsp;</p> <p>Table2: 'tbl_quotation'</p> <p>columns: seskey(pk) cutomer_id(fk) quotation_id(fk)&nbsp;&nbsp; rate&nbsp;&nbsp;&nbsp;&nbsp; no_of_test&nbsp;&nbsp;&nbsp;&nbsp; amount</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 100</p> <p>&nbsp;</p> <p>Table3: 'tbl_quotation_master'</p> <p>columns: seskey(pk)&nbsp;&nbsp; cutomer_id(fk)&nbsp;&nbsp;&nbsp; quotation_date</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IBM16042012</p> <p>&nbsp;</p> <p>As per your last post you have specified a <strong>userdid</strong> field&nbsp; in the query, so i am confused with this two post</p> <p>Ok let it be</p> <p><strong>If as per your first post if customerid is having datatype int in all the three tables,</strong></p> <p><strong>and now the data will be numeric in all the customerid fields so you cannot store IBMINDIA in customerid .</strong></p> <p><br> Now your query will be,</p> <p>SELECT&nbsp;<strong>t1.shortname&#43;' '&#43;convert(varchar(50),t3.quotation_date)</strong></p> <p>FROM tbl_partnerhirerege t1</p> <p>INNER JOIN tbl_quotation t2 ON t1.customeridd=t2.customerid</p> <p>INNER JOIN tbl_quotation_master t3 ON t2.customerid=t3.customerid</p> <p></p> 2012-04-17T04:08:01-04:004935819http://forums.asp.net/p/1793454/4935819.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>sorry i changed userdid field in three tables, my tables strucutre is&nbsp;</p> <p>Table1: 'tbl_partnerhirerege'<br> columns: seskey(pk) &nbsp; &nbsp;compannyname &nbsp; shortname &nbsp; &nbsp;address &nbsp; &nbsp; &nbsp; country &nbsp; &nbsp; userdid<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IBM PVTLMTD &nbsp; &nbsp; &nbsp; &nbsp;IBM &nbsp; &nbsp; &nbsp; &nbsp;BANGALORE &nbsp; &nbsp; INDIA &nbsp; &nbsp; &nbsp; 1<br> Table2: 'tbl_quotation'<br> columns: seskey(pk) &nbsp; userdid(fk) quotation_id(fk) &nbsp; rate &nbsp; &nbsp; no_of_test &nbsp; &nbsp; amount<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 100<br> Table3: 'tbl_quotation_master'<br> columns: seskey(pk) &nbsp; userdid(fk) &nbsp; &nbsp;quotation_date&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IBM16042012</p> 2012-04-17T05:17:06-04:004935831http://forums.asp.net/p/1793454/4935831.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>Hi,</p> <p>Ok no problem simply use userdid instead of customerid</p> <p>SELECT <strong>t1.shortname&#43;' '&#43;convert(varchar(50),t3.quotation_date)</strong></p> <p>FROM tbl_partnerhirerege t1</p> <p>INNER JOIN tbl_quotation t2 ON t1.userdid=t2.userdid</p> <p>INNER JOIN tbl_quotation_master t3 ON t2.userdid=t3.userdid</p> 2012-04-17T05:23:37-04:004935862http://forums.asp.net/p/1793454/4935862.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>hi, i used your code. its working fine. But</p> <p>ALTER procedure [dbo].[SP_QUOTATION_JOIN]<br> @userid INT<br> as<br> SELECT t1.shortname&#43;' '&#43;convert(varchar(50),t3.quotation_date)</p> <p>FROM tbl_partnerhirerege t1</p> <p>INNER JOIN tbl_quotation t2 ON t1.userdid=t2.userdid</p> <p>INNER JOIN tbl_quotation_master t3 ON t2.userdid=t3.userdid</p> <p></p> <p>when i execute @userid=8 then output is coming below</p> <p>IBM Apr 4 2012 12:00AM<br> IBM Apr 4 2012 12:00AM<br> IBM Apr 4 2012 12:00AM<br> IBM Apr 4 2012 12:00AM<br> IBM Apr 4 2012 12:00AM<br> IBM Apr 4 2012 12:00AM<br> HP &nbsp;Apr 6 2012 &nbsp;12.00AM</p> <p>But actually here&nbsp;HP &nbsp;Apr 6 2012 &nbsp;12.00AM in this row hp and date userdid is 9 in three tabels. But this record also coming when i execute @userdid=8. Can you tell me the problem</p> 2012-04-17T05:43:33-04:004935953http://forums.asp.net/p/1793454/4935953.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>hi, thank you so much all.</p> <p>its working.</p> 2012-04-17T06:33:57-04:004936481http://forums.asp.net/p/1793454/4936481.aspx/1?Re+join+for+three+tables+and+concatenate+two+columnsRe: join for three tables and concatenate two columns <p>Hi,</p> <p><strong>Change your stored procedure</strong> like below</p> <p>&nbsp;</p> <p>ALTER procedure [dbo].[SP_QUOTATION_JOIN] @userid INT</p> <p>as</p> <p>SELECT t1.shortname&#43;' '&#43;convert(varchar(50),t3.quotation_date)</p> <p>FROM tbl_partnerhirerege t1</p> <p>INNER JOIN tbl_quotation t2 ON t1.userdid=t2.userdid</p> <p>INNER JOIN tbl_quotation_master t3 ON t2.userdid=t3.userdid</p> <p><strong>where t1.userdid = @userid</strong></p> <p><strong></strong>&nbsp;</p> <p><strong>Please mark it as answer if it helped you out</strong></p> 2012-04-17T10:53:20-04:00