Solved

Convert sysdate to varchar(10)

Posted on 2008-10-24
4
1,080 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now