Convert DATE type

Advertisement
November 30

CreateFUNCTION [dbo].[dates](@strDate
NVARCHAR(10))
RETURNS Date
AS
BEGIN
DECLARE @strInputDate   
VARCHAR(10)
DECLARE @strOutPutDate  Date
DECLARE @strLen         
INT 
SELECT @strInputDate =
LTRIM(RTRIM(ISNULL(@strDate,
SELECT @strLen =
LEN(LTRIM(RTRIM(@strDate)))
IF CHARINDEX('0000', @strInputDate)
> 0 OR
CHARINDEX('*', @strInputDate)
> 0
BEGIN
SET @strOutPutDate
= ' '
END
ELSE
BEGIN
SELECT @strOutPutDate
= CONVERT(Date,
CAST(STUFF(STUFF(RIGHT('0'
+ @strInputDate, @strLen), 3, 0,
'-'), 6, 0,
AS DATE), 1)
END
RETURN ISNULL(@strOutPutDate,
END
SELECT [dbo].[dates](101213)
Result is: 2013-10-12
But i want the result to be as 10-12-13. What I am missing here

Advertisement

Replay

DECLARE
@dt VARCHAR(20)='101213'
SELECT
STUFF(STUFF(@dt,3,0,'-'),6,0,'-')
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

View 4 Replies

Tags:

  1. ovi upgrade via terminal
  2. connecting hp f4580 to bt hub 6
  3. 4.4.2verssion changer app
  4. windonw 8 graphics card dw
  5. nokia 6120c (B20.04) way
  6. FM VIEW_MAINTENANCE_CALL.
  7. R90M
  8. stepa89
  9. swimmingxgn
  10. B8T1
Copyrights 2019 Fcffair BigData Resource, All rights reserved