Sunday, February 19, 2012

I need help with a SQL Query

I know that there's a lot of you out there that are really good at Sql Queries. Hopefully, one of you will have pity on me and clue me in.

I am working with a Visual Studio 2005.net VB application accessing SQLServer 2005 and SQLServer Express databases.

I am using a sql query with ado.net data adapter to return data to a grid bound to the data adapter. My problem is that there is data in the SQL table stored as Bigint data types, that I need to divide by another integer and return as a double precision number.

For example, part of the Sql Statement looks like:

"InvStock.QuantitySold / NumPeriods AS 'AvgUnitsSold', "

It works except for the fact that it returns an integer and truncates the decimal points. Is there a way to return a double data type or a string formatted with a specified number of decimals?

CLW

Hi,

You need to perform a cast first.
Here is an example:

select BIGINTCOL, INTCOL, CAST(BIGINTCOL AS FLOAT) / CAST(INTCOL AS FLOAT) from DummyTable

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||

Don't forget to mark the question as answered when you've found an answer to your question.

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||

I will. sorry. I have been working like crazy and this is the firt I've checked back on this question.

CLW

No comments:

Post a Comment