x

Please let me know error in following code

CASE len(@a)
WHEN 6 THEN SET @hour = substring(a,1,2)
SET @min = substring(a,3,2)
SET @sec = substring(a,5,2)
WHEN 5 THEN SET @hour=substring(a,1,1)
SET @min=substring(a,2,2)
SET @sec=substring(a,4,2)
WHEN 4 THEN SET @min = substring(a,1,2)
SET @sec = substring(a,3,2)
END
more ▼

asked Oct 23, 2009 at 08:59 AM in Default

Sainath gravatar image

Sainath
11 1 1 1

What error message do you get? What is the problem with it?
Oct 23, 2009 at 09:23 AM graz ♦
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You dont need a CASE. It can be re-written as

select
@hour = substring(right('00'+@a,6),1,2),
@min = substring(right('00'+@a,6),3,2),
@sec = substring(right('00'+@a,6),5,2)
more ▼

answered Oct 23, 2009 at 09:50 AM

Madhivanan gravatar image

Madhivanan
1.1k 1 3 6

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1850
x41

asked: Oct 23, 2009 at 08:59 AM

Seen: 885 times

Last Updated: Oct 23, 2009 at 09:23 AM