Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Searching in two tables and add final result...
Searching in two tables and add final result to a string
Rate Topic
Display Mode
Topic Options
Author
Message
Minnu
Minnu
Posted Tuesday, December 04, 2012 1:01 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: 2 days ago @ 3:14 AM
Points: 116,
Visits: 355
Hi Team,
I got exact results from Team for whatever i've posted,
Very Very thanks.
Here my requirement is :
I have two tables,
table 1 : Test1
ColA | Value
----------------------
A 100
C 300
Table 2 : Test2
ColA | Value
-----------------------
B 200
D 150
if Record "A" is available in table1 then add string to a variable
@string = A : 300
else search in the table 2
Next
search for B, it is not available in table 1, then get from table 2
@ string = A : 300, B 200
am using below query for searching in table 1, how to include table 2 for searching.
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
Please help.........
Post #1392274
Bhuvnesh
Bhuvnesh
Posted Tuesday, December 04, 2012 2:19 AM
SSCrazy
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562,
Visits: 3,451
Minnu (12/4/2012)
am using below query for searching in table 1, how to include table 2 for searching.
you need to make JOIN with second table with first one.
-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1392293
Minnu
Minnu
Posted Tuesday, December 04, 2012 2:29 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: 2 days ago @ 3:14 AM
Points: 116,
Visits: 355
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.
table 1 : Test1
ColA | Value
----------------------
A 100
Table 2 : Test2
ColA | Value
-----------------------
B 200
if COLA =A is available in Table1 then
COLA : A Value: 100
else
check in Table2, if available
COLA : A Value: 100
Query Please...
Post #1392298
Sean Lange
Sean Lange
Posted Tuesday, December 04, 2012 8:00 AM
SSCrazy Eights
Group: General Forum Members
Last Login: 2 days ago @ 8:46 AM
Points: 8,547,
Visits: 8,204
Please stop cross posting. You don't need to start a new thread for each follow up question.
http://www.sqlservercentral.com/Forums/Topic1392324-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 Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1392509
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.