Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want an sql query that retrurn data from tables if today data is present if not then return no data

What I have tried:

select table1.coulumn1, table1.coulmn2 from patientTable group by date
Posted
Updated 12-Nov-20 22:37pm

That's complicated: You can retrieve data based on date:
SQL
SELECT Column1, Column2, DateColumn
FROM MyTable
WHERE DateColumn = CAST(GETDATE() AS DATE)

But you can't GROUP it without a lot of complication: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^]

[edit]
GETDATE added - somehow it got lost from the original...
[/edit]
 
Share this answer
 
v2
Comments
Member 14649324 13-Nov-20 2:55am    
@Griff But this query is also not working syntax error is it complete
OriginalGriff 13-Nov-20 3:36am    
Fixed: the GETDATE part got lost from my original, not sure how ...
Sorry about that.
Your question is far from clear. Perhaps you're looking for the EXISTS clause?
EXISTS (Transact-SQL) - SQL Server | Microsoft Docs[^]
SQL
SELECT
    SomeColumns
FROM
    YourTable
WHERE
    Exists
    (
        SELECT 1
        FROM YourTable
        WHERE YourDateColumn = CONVERT (date, SYSDATETIME())
    )
;
Or, if the column contains the date and time:
SQL
...
WHERE YourDateTimeColumn >= CONVERT (date, SYSDATETIME())
And YourDateTimeColumn < DateAdd(day, 1, CONVERT (date, SYSDATETIME()))
...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900