2017-08-18 14 views
1

where句で今日の日付を使用する必要があるクエリがあります。select * from where table = SQL Server Management Studioの今日の日付

元のクエリは次のとおりです。

select * 
from hist 
where checkdt = '8/18/2017' 
    and status = 'R' 
    and PSPAY is not null 

しかし、私は、get日付関数と日付を交換する必要があります。

select * 
from hist 
where checkdt = Today's Date 
    and status = 'R' 
    and PSPAY is not null 

私はGetDate()curdate()を使用しているが、それは動作しません。あなたが使用する必要があります

+1

checkdtのデータタイプを教えてください。 –

+0

@VidiyaPrasanth日時計 – user2116846

答えて

2

:SQL Serverでの

select h.* 
from hist h 
where checkdt = cast(getdate() as date) and 
     status = 'R' and 
     PSPAY is not null; 

を、cast()はまだインデックスを利用することができますので、これは最善のアプローチです。

+0

ありがとうございます – user2116846