Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 28th, 2003, 10:28 AM
desphera desphera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 desphera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question MS SQL Convert function not working

I have just converted an Access database to a SQLServer one and now have the joy(!!) of changing all the SQL statements to make then compatible.
In Access I had a Format function around a date, so now I am using a convert function which takes the form of convert(datetime,TABLE_NAME.COLUMN_NAME,n).

No matter what the number n is, the resultant date always comes out the same in m/d/yyyy format. This appears to go against everything I've read so far and cannot for the life of me work out what is going on.

Can anyone help?

Thanks
Desphera

Reply With Quote
  #2  
Old August 28th, 2003, 10:51 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
In SQL Server, the 'n' you speak of is the 'style'. What date style are you trying to set? I'll try it.

Reply With Quote
  #3  
Old August 28th, 2003, 10:54 AM
desphera desphera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 desphera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've tried most numbers between 101 and 113. See if you have any luck.

Reply With Quote
  #4  
Old August 28th, 2003, 11:09 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
You're right. I tried:

SELECT CONVERT(char(11), '12/12/2003', 111) As NewDate

...and it didn't work... Let me do some more research.

Last edited by dcarva : August 28th, 2003 at 11:25 AM.

Reply With Quote
  #5  
Old August 28th, 2003, 11:25 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
Go to this page, I tried teh first example, and it worked...

http://www.databasejournal.com/feat...10894_2197931_2

Still, I tried some other things and it didn't work as expected...

See if that helps.

Last edited by dcarva : August 28th, 2003 at 11:27 AM.

Reply With Quote
  #6  
Old August 28th, 2003, 06:01 PM
desphera desphera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 desphera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I just tried
SELECT * ,CONVERT(CHAR(19),'2003-01-22 10:31 PM',106)
FROM TABLE_NAME and it just returned '2003-01-22 10:31 PM' with each row. Tried it again with 111 and the same thing happened.

Is there perhaps something wrong with my installation of SQL Server?

I'm beginning to get frustrated with SQL Server already and I've only been using it a day or two. Come back Oracle, Access and MySQL, all is forgiven, or at least they do what the instructions say on the packet!!!

Reply With Quote
  #7  
Old September 1st, 2003, 04:40 AM
desphera desphera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 desphera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dcarva - thanks for your ideas but I'm still getting nowhere with this one, no matter which forums or sites I try to find answers on.
Just doesn't seem to make sense - anyone else out there got any ideas?

Reply With Quote
  #8  
Old September 1st, 2003, 06:03 AM
desphera desphera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 desphera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've found the problem......

The first parameter to the convert function is the datatype of the output string NOT the input column/second parameter).

There at last!!!!!

Reply With Quote
  #9  
Old September 1st, 2003, 11:03 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
Good job. Can you show me the code you used?

Reply With Quote
  #10  
Old September 1st, 2003, 11:07 AM
desphera desphera is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 6 desphera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
These now work fine

select CONVERT(varchar(11),FROM_DATE,106) FROM TABLE_NAME

or

select CONVERT(varchar(10),FROM_DATE,111) FROM TABLE_NAME

Reply With Quote
  #11  
Old April 2nd, 2004, 02:11 PM
billhay4 billhay4 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 billhay4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Convert function not working at all

I cannot get the Convert function to work at all

sending SQL statements in ASP.NET against an Access
2000 database. I keep getting an "undefined function" message.
In fact the only functions I can get working are DAY, Month, and Year,
but I have not been able to concatenate them to produce a dd/mm/yy
result.
Anyone got any suggestions? I would appreciate it.
Bill Hay

Reply With Quote
  #12  
Old April 5th, 2004, 12:29 PM
billhay4 billhay4 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 billhay4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem solved

When you query an Access 2000 database, the concatenation
operator seems to be & instead of +.
Haven't seen this in any of the stuff I've read, but that's how I got
my queries to work.
Bill Hay

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > MS SQL Convert function not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT