Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select a conditional date

Author  Topic 

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-06-30 : 10:13:49
Hello,

I want to insert a date to a table.
However the date should be as of today.
Not sure off hand the query.
The code looks like below

INSERT INTO EMPLOYEE_GROUP ([EMP_ID], [GRP_ID], [STR_ID], [EXP_DATE])
SELECT '1234', 'Cashier', ACTL_STR_ID, 'a date' from ARTS
Where EXP_DATE>getdate()



Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-30 : 10:28:35
What data type ist EXP_DATE?
Show example value for EXP_DATE please.
Explain exactly the daterange that is to insert into destination table from source table please.

Fred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-06-30 : 10:43:50
datetime type

6/30/2009 12:00:00 AM

The validated date is from tomorrow to the future.
I mean we can't select the day before today.
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-06-30 : 11:28:22
valid date is anything after tomorrow, and you cannot select day before today, so what about today?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-30 : 11:31:47
[code]Where EXP_DATE> dateadd(day, datediff(day, 0, getdate()), 0)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-06-30 : 11:36:09
Today is okay.
Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-06-30 : 12:01:56
Invalid column name 'EXP_DATE'

INSERT INTO EMPLOYEE_GROUP ([EMP_ID], [GRP_ID], [STR_ID], [EXP_DATE])
SELECT '1234', 'Cashier', ACTL_STR_ID, '06/25/2009' from ARTS
Where [EXP_DATE]>dateadd(day, datediff(day, 0, getdate()), 0)
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-06-30 : 12:03:26
check your arts table, use whatever date you want to use.
Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-06-30 : 12:12:14
There is no EXP_DATE column in the table ARTS.
I only want to get ACT_STR_ID from ARTS.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-30 : 12:31:22
[code]
INSERT INTO EMPLOYEE_GROUP ([EMP_ID], [GRP_ID], [STR_ID], [EXP_DATE])
SELECT '1234', 'Cashier', ACTL_STR_ID, dateadd(day, datediff(day, 0, getdate()), 0)
from ARTS
Where EXP_DATE>getdate()
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

zhshqzyc
Posting Yak Master

240 Posts

Posted - 2009-06-30 : 13:31:20
Well, the application is very complex.
The EXP_DATE actually is imported from outside as a variable.
The purpose is to disallow to select the day before today.

I hope the sql code like

INSERT INTO EMPLOYEE_GROUP ([EMP_ID], [GRP_ID], [STR_ID], [EXP_DATE])
SELECT '1234', 'Cashier', ACTL_STR_ID, @tempDate from ARTS
where someday_after_today_condition
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-30 : 13:33:38
[code]
INSERT INTO EMPLOYEE_GROUP ([EMP_ID], [GRP_ID], [STR_ID], [EXP_DATE])
SELECT '1234', 'Cashier', ACTL_STR_ID, @tempDate from ARTS
where @tempDate>= dateadd(dd,datediff(dd,0,getdate()),1)
[/code]
Go to Top of Page
   

- Advertisement -