Solved

Convert sysdate to varchar(10)

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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…

773 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