Joshua Java

Posts Tagged ‘sql server

Average of a datetime datatype field in SQL Server 2000

Posted by: Joshua on: June 14, 2008

In SQL Server 2000 you can not use the AVG() function on a datetime datatype field. So how do you get the average for a datetime datatype field?
This is the nasty way to do it:
convert(varchar, convert(datetime, avg(convert(real, end_time – start_time))), 108 ) avg_call_length

In the example I subtracted two fields: start_time and end_time to get the [...]

Adding extra char infront with SQL Server 2000

Posted by: Joshua on: June 13, 2008

Recently I’ve got a table with a field that the values needed to have an extra character infront of it. Each record must have extra zero infront of it and in the end the total character must be 10 characters long. So if I have a record with code: 12345, it should be transformed to [...]