Solved

Convert sysdate to varchar(10)

Posted on 2008-10-24
4
1,084 Views
Last Modified: 2013-11-16
I need to convert sysdate to a varchar(10) field and just include the date not the time in that field, what would be the proper casting or syntax for this?
0
Comment
Question by:wyogirl77
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:jamesgu
ID: 22797847
SELECT CONVERT(VARCHAR(10), GETDATE() , 102)
SELECT CONVERT(VARCHAR(10), GETDATE() , 121)
...

check this

http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx
0
 

Author Comment

by:wyogirl77
ID: 22798583
Would this work then, I am not sure about the else clause basically what I wanted to do was if the OutOfOfficeUntilDate is null I want to insert the system date into that field otherwise just continue on?

CREATE TRIGGER trg_Asgnmnt_OutOfOffice ON dbo.Asgnmnt
FOR UPDATE
AS
      IF UPDATE(OutOfOffice) BEGIN
            UPDATE      dbo.Assignee
               SET      OutOfOffice = I.OutOfOffice,
                  OutOfOfficeUntilTime = I.OutOfOfficeUntilTime,
                  OutOfOfficeUntilDate = I.OutOfOfficeUntilDate
                  if OutOfOfficeUntilDate is Null then SET OutOfOfficeUntilDate = CONVERT(Varchar(10), GETDATE(), 101) ELSE OutOfOfficeUntilDate = OutOfOfficeUntilDate
            FROM      dbo.Assignee A,
                  INSERTED I
            WHERE      A.LoginID = I.LoginID
              AND      I.CallID = '00010000'
      END
GO
0
 
LVL 9

Accepted Solution

by:
jamesgu earned 125 total points
ID: 22798750
            if OutOfOfficeUntilDate is Null then SET OutOfOfficeUntilDate = CONVERT(Varchar(10), GETDATE(), 101) ELSE OutOfOfficeUntilDate = OutOfOfficeUntilDate


change this to

SET OutOfOfficeUntilDate = isnull( CONVERT(Varchar(10), GETDATE(), 101) , OutOfOfficeUntilDate )
0
 

Author Closing Comment

by:wyogirl77
ID: 31509720
Great Thank you so much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sql to Replace Folderpath string in MS Access Table field 7 37
Update cached table in H2 database 6 43
SQL query bug 3 28
Process mapping 5 25
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now