formatting in sql server

Thread Solved
Reply

Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #11
Dec 23rd, 2008
In your Select statement add this
  1. SELECT CONVERT(VARCHAR(5), [dateTimeColumn], 14), ..... FROM [table name];
Last edited by Ramy Mahrous; Dec 23rd, 2008 at 10:27 am.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #12
Dec 23rd, 2008
Now my sql statement looks like this:
  1. SELECT CONVERT(VARCHAR(5), [dateTimeColumn], 14) * FROM PROGRAM WHERE DATE >= convert(VARCHAR, GETDATE()) AND DATE <= DATEADD(MONTH, 2, GETDATE())";
  2.  

the column that there is a problem with is not a dateTime. It is varchar(50).

her you can see the error message:
http://radio.web.surftown.dk/udsendelser.aspx
Last edited by peter_budo; Dec 24th, 2008 at 6:43 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #13
Dec 23rd, 2008
Because your SQL Syntax is wrong
the right one is
  1. SELECT CONVERT(VARCHAR(5), [dateTimeColumn], 14) , txt FROM PROGRAM WHERE DATE >= convert(VARCHAR, GETDATE()) AND DATE <= DATEADD(MONTH, 2, GETDATE())";
  2.  
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #14
Dec 23rd, 2008
ok now there is another error: Invalid column name 'dateTimeColumn'.

What is there supposed tol be in: [dateTimeColumn]?
I think that is the problem.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #15
Dec 23rd, 2008
Kischi, it seems you in hurry!!! please be patient and think in codes before writing it. dateTimeColumn isn't column in your table program, rather I mean the column holds the date data.
Tell me your table columns if you faced another problem.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #16
Dec 23rd, 2008
I'm sorry that I was in such a hurry. But I actually tried something else, but it didn't work.

I have 4 columns in the db. Here is hor it looks with the datatypes:

ID(bigint)
tid(varchar(50))
txt(text)
date(datetime)

It is tid that writes it like this: 30-12-1899 18:00:00

so that is the one I want to format.
so now I wrote [tid] instead of [dateTimeColumn]
But now I get another error: DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'tid'.

You can see it on: http://radio.web.surftown.dk/udsendelser.aspx

Hope this helps?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #17
Dec 23rd, 2008
Remove the container control (DataList, Repeater, etc...) and insert someone again... or try asking asp.net forum http://www.daniweb.com/forums/forum18.html
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #18
Dec 24th, 2008
I found out that it has nothing to do with my coding. It is excel that writes: 30-12-1899 18:00:00 when I write 18:00 automatically.

So do you know anything about excel, because have tried to change it so it dousn't do it, but I don't know how?

Thanks
Kischi
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: formatting in sql server

 
0
  #19
Dec 24th, 2008
let your SQL holds the date in any format, we won't care!!! what I care about? is date when returns, I suggest you a SQL statement to solve all of your problems.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kischi is an unknown quantity at this point 
Solved Threads: 0
kischi kischi is offline Offline
Light Poster

Re: formatting in sql server

 
0
  #20
Dec 25th, 2008
But is that also possible when the datatype of the column is "Varchar(50)" and it is not "datetime"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC