Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:42:18+00:00 2026-06-03T12:42:18+00:00

I am getting conversion error when running the below sql in store procedure becasue

  • 0

I am getting conversion error when running the below sql in store procedure becasue of some reason I can’t cast into varchar

Declare @sql varchar(100)
Declare @ddtime datetime

set @ddtime = '2012-02-03 22:14:50.057'

set @sql = 'select * from table1 where tdate='+@ddtime

exec(@sql)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:42:23+00:00Added an answer on June 3, 2026 at 12:42 pm

    You need to convert the @ddtime to a varchar since you are including it in a string:

    Declare @sql varchar(100)
    Declare @ddtime datetime
    
    set @ddtime = '2012-02-03 22:14:50.057'
    
    set @sql =  'select * from table1 where tdate= '''+ convert(nvarchar(25), @ddtime, 121) + ''''
    
    exec(@sql)
    

    or just have you @ddtime as a varchar instead of a datetime.

    Declare @ddtime varchar(25)
    

    The convert(varchar(25), @ddtime, 121) leaves your date in the same format that you initially set it as.

    How to format datetime & date in Sql Server

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data
can anybody tell me the reason why I m getting this error: conversion to
I am getting this error while developing a stored procedure Implicit conversion of varchar
Microsoft SQL Server 2008 (SP1), getting an unexpected 'Conversion failed' error. Not quite sure
I'm trying to compile some code, but I'm getting an error: Error invalid conversion
I'm getting this error: ORA-06502: PL/SQL: numeric or value error: character to number conversion
I am getting the following error: Conversion failed when converting the varchar value '2010-01-10'
I am getting a conversion error every time I try to submit a date
I am getting the error Conversion failed when converting date and/or time from character
I'm getting a compile error conversion from 'int*' to non-scalar type 'foo< int>' requested

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.