|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, June 07, 2010 4:59 AM
Points: 8,
Visits: 17
|
|
create procedure USP_InsertStatusText(@Statustext char(150),@RecievedBy varchar(50),@Deliverydate datetime) as BEGIN declare @date datetime set @Deliverydate=select @Deliverydate convert(varchar(),getdate(),1)as[mm/dd/yy] from TB_StatusEntry insert into TB_StatusText values(@Statustext,@RecievedBy,@Deliverydate) END
i want to convert the Delivery date to mm/dd/yyyy format but am getting error as Msg 156, Level 15, State 1, Procedure USP_InsertStatusText, Line 5 Incorrect syntax near the keyword 'select'.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 4:37 PM
Points: 2,248,
Visits: 5,352
|
|
Kavya,, try this:
create procedure USP_InsertStatusText(@Statustext char(150),@RecievedBy varchar(50),@Deliverydate datetime) as BEGIN declare @date datetime
set @Deliverydate= convert(varchar,@Deliverydate,1) --as [mm/dd/yy] from TB_StatusEntry
insert into TB_StatusText values(@Statustext,@RecievedBy,@Deliverydate)
END
But i tell, you, please store the date field in DateTime and NOT in some other formats.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, June 07, 2010 4:59 AM
Points: 8,
Visits: 17
|
|
is that date vill be In mm/dd/yyyu format
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 4:37 PM
Points: 2,248,
Visits: 5,352
|
|
| Yes it will be.. but if u be bit more specific on what you need, then v might provide a better solution..
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, June 14, 2010 12:43 AM
Points: 6,
Visits: 9
|
|
The Below SQL Command ------------ SELECT CONVERT (VARCHAR,GETDATE(),101) [Date] Here GETDATE() is Date field of Table. -- Out Put->mm/dd/yyyy
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Saturday, February 23, 2013 11:07 AM
Points: 1,103,
Visits: 1,170
|
|
Couple of basic things ...
Generally you don't want to worry about formatting on the database side. The db should just be storing the date as a date ... the user interface is where the formatting should take place. If you have to format on the db side, what you're going to end up with after using the convert function is a varchar, so it won't work to store that in a datetime variable ... the datetime variable will not maintain your format, it will just be whatever the standard datetime format is on your system. For example, on my system:
declare @date datetime set @date = CONVERT(varchar(10),getdate(),101) select @date returns
--2010-06-09 00:00:00.000 while
declare @date varchar(10) set @date = CONVERT(varchar(10),getdate(),101) select @date returns
--06/09/2010 Again though, you really don't want to store any dates as varchar/char fields ever ... you'll just end up with a mess.
And also, this may seem trivial, but anywhere you're doing an insert into a table, you should specify the columns you're inserting into in the correct order. This will allow you to avoid problems should the column order of the table ever change.
└> bt
Forum Etiquette: How to post data/code on a forum to get the best help
|
|
|
|