Select from Multiple statements and a query string

Posted by Sina under Sql Server on 6/6/2012 | Points: 10 | Views : 631 | Status : [Member] | Replies : 3
Hi i need a help...i have a page and the data for that page should come from 2 tables and the rows are to be extracted using an id which is stored as query string...I have put a sample as to what i want from the tables:
(select [some fields] from Title) and (select [some fields] from Reply) where TitleId=@id
TitleId is common in both tables and @id is the query string....

@Sina


Responses

Posted by: .Netlearner on: 6/6/2012 [Member] Starter | Points: 25

Up
0
Down
First Extract the @id from the querystring,Convert it to the datatype that matches ut TitleID.

now use the query as follows,

select t.Somefield1,t.Somefield2,r.Somefield1,r.Somefield2 from Title t,Reply r where t.TitleID=r.TitleID and t.TitleID=@id

Sina, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sina on: 6/6/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you...il try it

@Sina

Sina, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/11/2012 [Member] Bronze | Points: 25

Up
0
Down
We use Joins here

select t.Somefield,r.Somefield from Title t inner join Reply r on t.TitleID=r.TitleID where t.TitleID=@id

Sina, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response