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 2012 Forums
 Transact-SQL (2012)
 insert records for today only

Author  Topic 

djamit
Starting Member

17 Posts

Posted - 2013-07-29 : 11:58:31
I have a Table with patients scheduled for a CT.
I want to insert some columns of that table to a worklist table.
One of the column (Schedele) is a datetime column.
I want to insert only the scheduled patients for today in the worklist table (in the StartDate column).

How can I solve this?

for now I use:
INSERT INTO[WorkList] (AccessionN, PatientID, PatientNam, Modality, StartDate)
SELECT Sch_Id, IDA, PAT_NAME, LOCATION, Schedule
FROM EZIS

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-29 : 12:44:52
Add a where clause like this:
INSERT INTO[WorkList] (AccessionN, PatientID, PatientNam, Modality, StartDate)
SELECT Sch_Id, IDA, PAT_NAME, LOCATION, Schedule
FROM EZIS
WHERE StartDate >= DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),0)
AND StartDate < DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),1)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-30 : 02:17:28
it should be the below as per OPs explanation


INSERT INTO[WorkList] (AccessionN, PatientID, PatientNam, Modality, StartDate)
SELECT Sch_Id, IDA, PAT_NAME, LOCATION, Schedule
FROM EZIS
WHERE Schedule >= DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),0)
AND Schedule < DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()),1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

djamit
Starting Member

17 Posts

Posted - 2013-07-30 : 10:03:18
thank you it works
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-31 : 02:09:08
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -