December 4, 2012 at 3:20 am
Hi Team,
I have two tables,
table 1 : Test1
ColA|Value
----------------------
A100
Table 2 : Test2
ColA|Value
-----------------------
B200
if COLA =A is available in Table1 then
COLA : A Value: 100
else
check in Table2, if available
COLA : A Value: 100
Searching for a string in two tables using joins
A : 300
B : 200
c : 300
d : 150
Yes, Using joins..
First it need to check in table1, if value found then assign that values to a string,
if not found then only it should check in table2
for Table1 am using below code
---------------------------------
SELECT RTRIM(
+ 'ColA:'+ISNULL(ColA,'')+', '
+ ISNULL('ColB:'+CAST(ColB AS VARCHAR(10))+' ','')
+ ISNULL('ColC:'+CAST(ColC AS VARCHAR(10))+' ','')
+ ISNULL('ColD:'+CAST(ColD AS VARCHAR(10))+' ','')
)
FROM
for table 2 am using below code:
---------------------------------------
select @query1 = (SELECT
CASE WHEN Col1 IS NULL or Col1 = '' THEN ''
ELSE CASE WHEN Value IS null then
'Col1: ' + rtrim(Col1) +CHAR(10)
ELSE 'Col1: ' +rtrim(usage_rights) + ' (Col2 ' + rtrim(convert(varchar, Value,107)) + ')' +CHAR(10)
END
END +
i want a final code by joining two tables and assign a final string to a variable @query1
Plz Help
December 4, 2012 at 5:27 am
This was removed by the editor as SPAM
December 4, 2012 at 8:01 am
Isn't this the same question you posted yesterday??
http://www.sqlservercentral.com/Forums/Topic1391849-391-1.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply