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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 insert records for today only
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

djamit
Starting Member

17 Posts

Posted - 07/29/2013 :  11:58:31  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/29/2013 :  12:44:52  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 07/30/2013 :  02:17:28  Show Profile  Reply with Quote
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 - 07/30/2013 :  10:03:18  Show Profile  Reply with Quote
thank you it works
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 07/31/2013 :  02:09:08  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000