how to find contactid in sql server?
RCustomerId GiftRegistryId ContactId DateActive DateExpire
----------- -------------- --------- ---------- ----------
62 66 225 NULL 2010-10-11
62 66 228 2010-10-13 NULL
62 67 229 NULL 2010-10-20
62 67 230 2010-10-21 NULL
62 68 232 NULL NULL
To check today date is >= dateexpire
if it is >= i want to check same giftregistryid dateactive date wheather is >= or not.
if geater then equal i no need to display contactid otherwise display contactid.
Eg : 开发者_C百科 Consider today date id 2010-10-11
result is Contactid
228
229
You could try:
SELECT ContactId FROM TableName
WHERE GetDate() BETWEEN DateActive AND DateExpire
You'll definitely have to fudge things around by using ISNULL for null dates (I'd include it, but, based on your question, I can't tell how NULL values are handled).
I think what you want is
SELECT
contactid
FROM
yourtable
WHERE
dateactive >= '2010-10-11' OR dateactive IS NULL AND
dateexpire <= '2010-10-11' OR dateexpire IS NULL
but it's really hard to understand, sorry.
精彩评论