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. using outline load utility
  2. 30LF
  3. vendor mass confirmation sap
  4. DCD5
  5. stepa89
  6. package4uu
  7. underlinewgn
  8. S4VP
  9. 2K38
  10. commonk5t
Copyrights 2019 Fcffair BigData Resource, All rights reserved