I know this is not valid syntax, but my select statement below shows what I am trying to accomplish. What do I need to alter in order to succesfully run this select query?
Declare @Data Table
(
nID varchar(100)
,name varchar(100)
,saletotals float
,saledate date
)
Declare @GiveMeSaleTotals Table
(
nID varchar(100)
,datetocheck date
)
Insert into @Data (nID, name, saletotals ,saledate) Values
('111eee', 'Blue', '13.22', '01/01/2016')
,('111eee', 'Blue', '44.11', '01/03/2016')
,('111eee', 'Blue', '22.11', '01/08/2016')
,('222ffff', 'Red', '11.11', '01/11/2016')
,('222ffff', 'Red', '22.10', '01/22/2016')
,('4444ffff', 'Red', '22.10', '12/05/2016')
,('4444ffff', 'Red', '21.10', '12/05/2016')
Insert Into @GiveMeSaleTotals (nID, datetocheck) Values
('1111eee', GetDate())
Select
*
FROM @Data
WHERE nID IN (Select nID from @GiveMeSaleTotals where @Data.saledate = datetocheck)
Best Answer
It's not completely clear what you're trying to do, but this might help:
results in:
Rextester link: http://rextester.com/SPJQX46455