ciao a tutti e grazie!
SELECT 1/COUNT(*) FROM pubs.dbo.authors
ti ritorna 0 perche' il risultato viene "castato"
al tipo dato int.
Puoi ingannarlo semplicemente con:
SELECT 1.0/COUNT(*) FROM pubs.dbo.authors
Oppure piu' formalmente puoi fare il cast a mano definendo
il tipo dato da utilizzare:
SELECT CAST(1 AS numeric(5, 2))/COUNT(*)FROM pubs.dbo.authors
Ciao,
--
Gianluca Hotz
Backoffice MVP (SQL Server) MCP SQL Server and MCP Windows
Founding member of the Italian User Group for SQL Server
http://www.ghotz.com
http://www.ugiss.org
"adry" <adrian...@hotmail.com> wrote in message
news:r2P97.23083$%7.30...@news6.giganews.com...
SELECT CAST(1 AS numeric(5, 2))/COUNT(*)
FROM pubs.dbo.authors
WHERE au_lname = 'paperino'
ritorna, giustamente, un errore.
Tutto cio' e' coerente, ma alle volte e' piu'
pratico non seguire strettamente le regole
matematiche ;-)
SELECT CASE WHEN COUNT(*) = 0 THEN 0
ELSE CAST(1 AS numeric(5, 2))/COUNT(*)
END AS MioCampo
FROM pubs.dbo.authors
WHERE au_lname = 'paperino'
Ti permette di avere 1/0 = 0 oppure puoi
sotituire in valore 0 dopo la then con
un valore NULL
Ciao,
--
Gianluca Hotz
Backoffice MVP (SQL Server) MCP SQL Server and MCP Windows
Founding member of the Italian User Group for SQL Server
http://www.ghotz.com
http://www.ugiss.org
"adry" <adrian...@hotmail.com> wrote in message
news:r2P97.23083$%7.30...@news6.giganews.com...
"Gianluca Hotz" <gh...@alphasys.it> wrote in message
news:eVVsywmGBHA.1484@tkmsftngp05...