Conversion failed when converting the varchar value 'o' to data type int.

I get  the following error:-

Msg 245, Level 16, State 1, Server XXXXXXXXXX, Procedure GetPOS, Line 78
Conversion failed when converting the varchar value 'o' to data type int.

Due to this line:-

SET @CurrentDate = CONVERT(bigint, REPLACE(CONVERT(varchar(10),GETDATE(),121),'-',''));

This only occurs rarely and i am trying to eliminate it happening, so maybe there is a better way to get the current date int the format I need, which is YYYYMMDD
missing_dllAsked:
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.

Ryan ChongCommented:
try:

SET @CurrentDate = CONVERT(INT, CONVERT(varchar(10),GETDATE(),112))
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
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Do you really want the date as 8 digit integer?
0
missing_dllAuthor Commented:
Do you really want the date as 8 digit integer?

Why not, please explain ?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
It is just uncommon. You usually store dates as dates, to allow for date algebra (how many months are between date1 and date2?). You can't really do much with an "integer" date.
1
missing_dllAuthor Commented:
It is just uncommon. You usually store dates as dates, to allow for date algebra (how many months are between date1 and date2?). You can't really do much with an "integer" date.

In our database the date is stored as an Int with YYYYMMDD, which we do not perform any date calculations on. It is more just to pull information out of the database table using a WHERE command, i.e. WHERE @CurrentDate = 20150716
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That works with exact dates and ranges, but no dynamic intervals, so should be fine for you.
0
missing_dllAuthor Commented:
Will put this in production and see if we have an occurrence of the issue again
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.