473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQL Server Script to get Date Format

radcaesar
759 Expert 512MB
Hi all,
I Want a sql script which gets the DateFormat of the SQL Server (Whether its dmy or mdy etc). The Script should have to run in both sqlserver 2000 and 2005.

Solutions pls.
Jan 11 '07 #1
10 9401
iburyak
1,017 Expert 512MB
I am not sure if I understand your question.... :(
Jan 11 '07 #2
when u got script then send me...<Email removed>
Apr 24 '07 #3
Hi iburyak,

I want your help in writing function

I want to write a function which converts number to word

for example : 1200 to twelve hundred

Please mail me at <Removed>

byeee
May 1 '07 #4
iburyak
1,017 Expert 512MB
Try this:
1. Create Function
[PHP]
Create Function fnWriteNumber (@Number varchar(255))
Returns varchar(1000)
AS
BEGIN
declare @LookupNumber table(
ID int Primary Key,
Description varchar(255))

insert into @LookupNumber values (1,'One')
insert into @LookupNumber values (2,'Two')
insert into @LookupNumber values (3,'Three')
insert into @LookupNumber values (4,'Four')
insert into @LookupNumber values (5,'Five')
insert into @LookupNumber values (6,'Six')
insert into @LookupNumber values (7,'Seven')
insert into @LookupNumber values (8,'Eight')
insert into @LookupNumber values (9,'Nine')

insert into @LookupNumber values (10,'Ten')
insert into @LookupNumber values (11,'Eleven')
insert into @LookupNumber values (12,'Twelve')
insert into @LookupNumber values (13,'Thirteen')
insert into @LookupNumber values (14,'Fourteen')
insert into @LookupNumber values (15,'Fifteen')
insert into @LookupNumber values (16,'Sixteen')
insert into @LookupNumber values (17,'Seventeen')
insert into @LookupNumber values (18,'Eighteen')
insert into @LookupNumber values (19,'Nineteen')

insert into @LookupNumber values (20,'Twenty')
insert into @LookupNumber values (30,'Thirty')
insert into @LookupNumber values (40,'Forty')
insert into @LookupNumber values (50,'Fifty')
insert into @LookupNumber values (60,'Sixty')
insert into @LookupNumber values (70,'Seventy')
insert into @LookupNumber values (80,'Eighty')
insert into @LookupNumber values (90,'Ninety')

Declare @Ret varchar(1000)
IF Len(@Number) = 1
Return (Select Description From @LookupNumber Where ID = @Number)
ELSE IF Len(@Number) = 2
Select @Ret = Isnull((Select Description From @LookupNumber Where ID = Right(@Number, 2)),
(Select Description From @LookupNumber Where ID = Left(Right(@Number, 2),1) + '0') + ' ' +
(Select Description From @LookupNumber Where ID = Right(@Number, 1))
)
ELSE IF Len(@Number) = 3
Select @Ret = (Select Description From @LookupNumber Where ID = Left(@Number,1)) + ' Hunderd ' +
Isnull((Select Description From @LookupNumber Where ID = Right(@Number, 2)),
(Select Description From @LookupNumber Where ID = Left(Right(@Number, 2),1) + '0') + ' ' +
(Select Description From @LookupNumber Where ID = Right(@Number, 1))
)
ELSE IF Len(@Number) = 4
Select @Ret = (Select Description From @LookupNumber Where ID = Left(@Number,1)) + ' Thousand ' +
(Select Description From @LookupNumber Where ID = Left(@Number,1)) + ' Hunderd ' +
Isnull((Select Description From @LookupNumber Where ID = Right(@Number, 2)),
(Select Description From @LookupNumber Where ID = Left(Right(@Number, 2),1) + '0') + ' ' +
(Select Description From @LookupNumber Where ID = Right(@Number, 1))
)

RETURN @Ret
END

go[/PHP]

2. Call Function
[PHP]select dbo.fnWriteNumber(1206)[/PHP]

Good Luck.
May 1 '07 #5
HelenT
1
Hello,
Firstly - thank you for the function - it was exactly what I needed!

I did spot a few issues with it though that I have tweaked and thought you might like to know:

1) Lines 48 and 65 - Hundred spelt Hunderd
2) Line 41
Single digits don't return correctly - had to replace Return here with Set @Ret =
The final Return @Ret (line 61) seems to be overriding it
3) Line 55
Thousand update repeats the 'thousand' digit twice e.g. 1250 becomes One Thousand One Hundred Fifty
I've replaced the second digit check with Substring(@Number,2,1)
4) Lines 48 and 65 I added an 'and' after the Hundred because it 'reads nicer'
e.g. Three Thousand Six Hundred and Fifty Two
Jul 6 '07 #6
ck9663
2,878 Expert 2GB
Hello,
Firstly - thank you for the function - it was exactly what I needed!

I did spot a few issues with it though that I have tweaked and thought you might like to know:

1) Lines 48 and 65 - Hundred spelt Hunderd
2) Line 41
Single digits don't return correctly - had to replace Return here with Set @Ret =
The final Return @Ret (line 61) seems to be overriding it
3) Line 55
Thousand update repeats the 'thousand' digit twice e.g. 1250 becomes One Thousand One Hundred Fifty
I've replaced the second digit check with Substring(@Number,2,1)
4) Lines 48 and 65 I added an 'and' after the Hundred because it 'reads nicer'
e.g. Three Thousand Six Hundred and Fifty Two

kindly post the final version....

thanks
Jul 6 '07 #7
srinit
43
kindly post the final version....

thanks

HI ,
I have the same requirement.kindly post the final verson
Jul 10 '07 #8
srinit
43
kindly post the final version....

thanks

HI ,
I have the same requirement.kindly post the final verson
Jul 10 '07 #9
Hi all,
I Want a sql script which gets the DateFormat of the SQL Server (Whether its dmy or mdy etc). The Script should have to run in both sqlserver 2000 and 2005.

Solutions pls.

HI, i was seeing the blog and notice that you have the same problem that I have. By nay chance you managed to solve it? you already know how to detect the date format of SQL?
Sep 6 '07 #10
This is for "ck9663", "srinit", and any of the other folks who couldn't be bothered troubleshooting things on their own.... despite "HelenT" explaining ways to get around the original code's issues...

Expand|Select|Wrap|Line Numbers
  1. Create Function fnWriteNumber (@Number varchar(255)) 
  2. Returns varchar(1000) 
  3. AS
  4. BEGIN
  5. declare @LookupNumber table (ID int Primary Key, Description varchar(255))
  6. insert into @LookupNumber values (1,'One')
  7. insert into @LookupNumber values (2,'Two')
  8. insert into @LookupNumber values (3,'Three')
  9. insert into @LookupNumber values (4,'Four')
  10. insert into @LookupNumber values (5,'Five')
  11. insert into @LookupNumber values (6,'Six')
  12. insert into @LookupNumber values (7,'Seven')
  13. insert into @LookupNumber values (8,'Eight')
  14. insert into @LookupNumber values (9,'Nine')
  15. insert into @LookupNumber values (10,'Ten')
  16. insert into @LookupNumber values (11,'Eleven')
  17. insert into @LookupNumber values (12,'Twelve')
  18. insert into @LookupNumber values (13,'Thirteen')
  19. insert into @LookupNumber values (14,'Fourteen')
  20. insert into @LookupNumber values (15,'Fifteen')
  21. insert into @LookupNumber values (16,'Sixteen')
  22. insert into @LookupNumber values (17,'Seventeen')
  23. insert into @LookupNumber values (18,'Eighteen')
  24. insert into @LookupNumber values (19,'Nineteen')
  25. insert into @LookupNumber values (20,'Twenty')
  26. insert into @LookupNumber values (30,'Thirty')
  27. insert into @LookupNumber values (40,'Forty')
  28. insert into @LookupNumber values (50,'Fifty')
  29. insert into @LookupNumber values (60,'Sixty')
  30. insert into @LookupNumber values (70,'Seventy')
  31. insert into @LookupNumber values (80,'Eighty')
  32. insert into @LookupNumber values (90,'Ninety')
  33.  
  34. Declare @Ret varchar(1000)
  35.  
  36. IF @Number < 10
  37.  
  38.     Select @Ret = Description From @LookupNumber Where ID = @Number
  39.  
  40. ELSE IF @Number < 100
  41.  
  42.     Select @Ret = Isnull((Select Description From @LookupNumber Where ID = Right(@Number, 2)),
  43.  
  44.      (Select Description From @LookupNumber Where ID = Left(Right(@Number, 2),1) + '0') + ' ' +
  45.  
  46.      (Select Description From @LookupNumber Where ID = Right(@Number, 1))
  47.  
  48.      )
  49.  
  50. ELSE IF @Number BETWEEN 100 AND 999
  51.  
  52.     Select @Ret = (Select Description From @LookupNumber Where ID = Left(@Number,1)) + ' Hundred ' +
  53.  
  54.   Isnull((Select Description From @LookupNumber Where ID = Right(@Number, 2)),
  55.  
  56.    (Select Description From @LookupNumber Where ID = Left(Right(@Number, 2),1) + '0') + ' ' +
  57.  
  58.    (Select Description From @LookupNumber Where ID = Right(@Number, 1))
  59.  
  60.    )
  61.  
  62. ELSE IF @NUMBER BETWEEN 1000 AND 9999
  63.  
  64.   Select @Ret = (Select Description From @LookupNumber Where ID = Left(@Number,1)) + ' Thousand ' +
  65.  
  66. (Select Description From @LookupNumber Where ID = Right(Left(@Number,2),1)) + ' Hundred ' +
  67.  
  68.     Isnull((Select Description From @LookupNumber Where ID = Right(@Number, 2)),
  69.  
  70.      (Select Description From @LookupNumber Where ID = Left(Right(@Number, 2),1) + '0') + ' ' +
  71.  
  72.      (Select Description From @LookupNumber Where ID = Right(@Number, 1))
  73.  
  74.     )
  75.  
  76.  
  77. RETURN @Ret 
  78.  
  79. END
  80.  
  81. go
  82.  
Sep 10 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution....
2
by: Scott Knapp | last post by:
Good Day - I have a form which sets the current date, as follows: <script type="text/javascript"> xx=new Date() dd=xx.getDate() mm=xx.getMonth()+1 yy=xx.getYear() mmddyy=mm+"/"+dd+"/"+yy...
1
by: Michael Albanese | last post by:
I am building an application to report on-the-job injuries and incidents. There are a lot of Date fields, some of which are optional and can be left blank by the user. I have allowed Nulls on...
0
by: ActiveUp | last post by:
http://www.activeup.com/products/components/activecalendar Active Calendar is an ASP.NET server control that allows users to select a date and/or time quickly using a professional looking date...
5
by: sandman | last post by:
I've been testing my web app on another workstation to simulate using the server time. The test pc's time is an hour behind the server time and when the user processes a request, the server time...
6
by: Willie wjb | last post by:
Hi, i have a client program that sends a filter expression to the server PC. On that server PC this filter is put over a datatable and the result is send back. the server can be located on a...
20
by: none | last post by:
I have managed to get the below script *almost* working. However, it still has a problem calculating the number of months. The date I am trying to calculate from is Oct 15, 1994. With the correct...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
5
by: Cloy | last post by:
The script below loads a calendar page in an iframe and scrolls to today's date. It works just dandy on my apache/linux server, but won't do anything when I use IIS. (Nothing appears on the page...
5
by: =?Utf-8?B?dXNmaW5lY2F0cw==?= | last post by:
I'm new to asp.net. I'm trying to follow the tutorial walkthroughs and have got a few done. Now I'm doing the one about validating input, and I've run into some problems. In particular, I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.