Help with scripting the SQL and show result

Dear expert, I want to write a script that first it does a SQLquery, and then it will count the query. for exemple: query will show a result of 145 row of data. I want first to show that this SQLquery is done and run in current date, if it's failed it will show the error message, then I want show the result of 145 number.

Is this possible to do? Thanks.
LVL 1
WeTiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Just use the @@ROWCOUNT variable to have the number of rows returned by the last query.
An error will always be thrown by the SQL Server engine if something happens, so I do not really understand your request here.

Example for the query and @@ROWCOUNT:
SELECT  *
FROM TableName
WHERE date_colname = GETDATE()

PRINT @@ROWCOUNT

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeTiAuthor Commented:
What is the output for @@ROWCOUNT? A number?
Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes. Just a number.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Vitor MontalvãoMSSQL Senior EngineerCommented:
I've used PRINT command but you can also use SELECT @@ROWCOUNT.
It really depends on how you're going to use it.
WeTiAuthor Commented:
Then I want this number to show in a xml file... this will be abit harder, and I also want this xml to show if error it will print out red text in the table.
Vitor MontalvãoMSSQL Senior EngineerCommented:
I can only answer the SQL Server part as I'm not used to work with XML.
I would suggest you to open a new question in XML topic so the right Experts can help you achieve what you want.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.