Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Insert Into

Status
Not open for further replies.

scorpoius

Programmer
Sep 4, 2002
1
US
I'm trying to use the insert into with a select statement to fill the first colum and I want a value I specify to fill the second colum. I'm doing this from vb use ado. I use the select statment to get the employee ID, but I don't know how to just throw some value in for AvailDate.
Any Tips?

sql = "INSERT INTO TmpEmpAvail (EmployeeID, AvailDate)
SELECT EmployeeID FROM EmpRTO WHERE (StartDate > &quot; & &quot;'&quot; & currentDate & &quot;'&quot; & &quot; OR EndDate < &quot; & &quot;'&quot; & currentDate & &quot;')&quot;
 
Code:
INSERT INTO TmpEmpAvail 
  (EmployeeID, AvailDate) 
SELECT EmployeeID, [i]date expression[/i]
 FROM EmpRTO

for date expression you could hardcode a date literal, e.g. '2002-09-05' -- but who wants to do that

the best value to &quot;just throw in&quot; is the current date, and all databases have a current date function

in ANSI SQL (this forum) it would be CURRENT DATE or CURRENT_DATE, i forget which

look for a date function like getdate() or sysdate() or now(), all of which can be used in your situation to insert the current date into the AvailDate column

you could even use the date function in a date expression, e.g. first day of the next quarter (eligibility for company sickleave)

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top