我有两个表和以下查询:
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
是否可以从Table1
中选择其他字段?
答案 0 :(得分:0)
当然,你的意思是这样吗?
Select
@Item = table1Id,
@Item2 = table2.Column1,
@Item3 = table2.Column2
From Table1
Inner Join table2 on table1.table1Id = table2.table1Id
...
答案 1 :(得分:0)
是的,您可以进行多项选择,SELECT item1, item2 FROM table1
等。
答案 2 :(得分:0)
肯定可以 -
DECLARE @item1 nvarchar(100)
DECLARE @item2 nvarchar(200)
select @item1 = <column1>, @item2 = <column2> from <table>
PRINT @item1
PRINT @item2
答案 3 :(得分:0)
如果我理解正确,那么是的,您可以分配多个值。
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