How to shorten a date when a query is run

I have an inline query in my C# code where I search a table based upon a date. The date value stored in the RegDate column
is the long format of the date '2015-08-26 00:01:56:107'

The issue here is that the @inParam date is in the short date format. So if @inParam = '2015-08-26'

The query will not work because the long form of the date has the time information. So, how do I shorten the
date ZARGOZA.RegDate when I perform the query below. Is there any function that will change ZARGOZA.RegDate
to the short date format?

SELECT COUNT(1) FROM ZARGOZA WHERE ZARGOZA.RegDate = @inParam
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
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.

sachiekCommented:
If you want Regdate to be in short date format always then you can cast it that way.
If you want @inParam to convert to short date then use that same way.

SELECT COUNT(1) FROM ZARGOZA WHERE cast([ZARGOZA.RegDate] as date) = @inParam

Open in new window

0

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
brgdotnetcontractorAuthor Commented:
Thank you
0
PortletPaulfreelancerCommented:
the alternative, with better performance implications, is to NOT ADJUST the DATA

SELECT COUNT(1) FROM ZARGOZA
WHERE ZARGOZA.RegDate >= @inParam
AND ZARGOZA.RegDate < DATEADD(day,1,@inParam)

That query has a single calculation, instead of one calculation per row of data.

This is known as a "saragble" set of predicates which meas that an index on ZARGOZA.RegDate will be effective. Basically: you should avoid passing data through functions to suit your where clause, instead alter the where clause to suit the data.
0
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
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.