x
login about faq Site discussion (meta-askssc)

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 '09 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 '09 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 '09 at 09:50 AM

Madhivanan gravatar image

Madhivanan
1.1k 1 2 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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1611
x36

asked: Oct 23 '09 at 08:59 AM

Seen: 550 times

Last Updated: Oct 23 '09 at 09:23 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.