The “object” type of SQL Server is hardly used and with good reason. RDBMS are meant to be “strongly typed“.. it is the foundation of the domain/type concept.
RDBMS : “What are you INSERTing Dave?”
Dave: “I don't know!“
RDBMS : “Get stuffed!”
Anyway I am knocking out a stored proc that returns “Quick Stats” to the client. Basically just UNIONing..
USE PUBS
GO
SELECT 'Sales Count' as Stat, COUNT(*) as Score
FROM sales
UNION ALL
SELECT 'Title Count', COUNT(*)
FROM titles
Too easy...But a request comes to include a “Last Date” statistic...
SELECT 'Sales Count' as Stat, COUNT(*) as Score
FROM sales
UNION ALL
SELECT 'Last Published', MAX(pubdate)
FROM titles
“So we sold '1900-01-22 00:00:00.000' titles?..Good work Dave.. You're fired!”
“But wait, I have a better idea..“
SELECT 'Sales Count' as Stat, CAST(COUNT(*) AS SQL_VARIANT) as Score
FROM sales
UNION ALL
SELECT 'Last Published', MAX(pubdate)
FROM titles
Print | posted on Wednesday, May 11, 2005 10:06 AM