views:

39

answers:

4

I have two tables and the following query:

table1
---------
table1Id(pk)
fromdate,
todate,
name,
link

table2
--------
table2Id(pk)
url
table1Id(fk)

SELECT  @ITEM = table1Id FROM table1
    WHERE 
        table1.FromDate <= @ToDate AND  @FromDate <= table1.ToDate  


select * from table2 where table1Id =@ITEM

Is it possible to select the other fields from Table1 as well?

A: 

Sure, do you mean something like this?

Select 
   @Item = table1Id, 
   @Item2 = table2.Column1, 
   @Item3 = table2.Column2 
From Table1
Inner Join table2 on table1.table1Id = table2.table1Id
...
Randy Minder
A: 

Yes, you can do multiple selections, SELECT item1, item2 FROM table1 etc.

Robert
A: 

Yes surely possible -

DECLARE @item1 nvarchar(100)
DECLARE @item2 nvarchar(200)

select @item1 = <column1>, @item2 = <column2> from <table>

PRINT @item1
PRINT @item2
Sachin Shanbhag
tnx.it worked fine..
A: 

If I understand you correctly, then yes, you can assign multiple values.

DECLARE @table1Id INT,
        @fromdate DATETIME,
        @todate DATETIME, 
        @name VARCHAR(20), 
        @link VARCHAR(20)

SELECT  @table1Id = table1Id
        @fromdate = fromdate, 
        @todate = todate, 
        @name = name, 
        @link = link
FROM    table1
WHERE   table1.FromDate <= @ToDate 
AND     @FromDate <= table1.ToDate
astander

related questions