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 7618435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:24:13+00:00 2026-05-31T03:24:13+00:00

I made the seemingly minor change of adding a 2nd variable to a stored

  • 0

I made the seemingly minor change of adding a 2nd variable to a stored procedure in sql server 2008 r2 that uses dynamic sql, and I’m getting a new error:

Msg 206, Level 16, State 2, Line 1
Operand type clash: date is incompatible with int

when I run the next code block below (the one following that is my sproc)

DECLARE @tableName varchar(120)
SET @tableName = 'tblDailySMA'
DECLARE @mxDate DATE
SET @mxDate = dbo.LatestDateWithPricingVolCountOver4k()
EXEC sprocAddDatesSymbolsAndPeriodsToAggregatedStudy @tableName, @mxDate

USE [Market]
GO
/****** Object:  StoredProcedure [dbo].[sprocAddDatesSymbolsAndPeriodsToAggregatedStudy]    Script Date: 03/11/2012 12:55:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sprocAddDatesSymbolsAndPeriodsToAggregatedStudy]
    @table varchar(120), @maxDate DATE

AS

EXEC(
    ';WITH t1 AS
    (
        SELECT Symbol, TradingDate
        FROM tblSymbolsMain
        CROSS JOIN tblTradingDays
        WHERE TradingDate <=' + @maxDate +
    '), 

    t2 AS
    (
        SELECT Symbol, TradingDate, Period
        FROM t1
        CROSS JOIN tblPeriods
    )

    INSERT INTO ' + @table + ' (Symbol, TradeDate, Period)
    (SELECT Symbol, TradingDate, Period
    FROM t2
    EXCEPT
        (SELECT t3.Symbol, t3.TradeDate, t3.Period
         FROM ' + @table + '))')

RETURN

I’m sure it’s a very simple quick fix, what am I overlooking? Thanks in advance.

  • 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-05-31T03:24:14+00:00Added an answer on May 31, 2026 at 3:24 am

    You need to surround date parameters with single quotes. And to embed those in dynamic SQL you need to escape them.

    '... WHERE TradingDate <= ''' + CONVERT(CHAR(8), @maxDate, 112) + ''' ...'
    

    Or to make it a little easier to read (depending on the person, I guess):

    '... WHERE TradingDate <= ' + CHAR(39) + CONVERT(CHAR(8), @maxDate, 112) + CHAR(39) + ' ...'
    

    Perhaps the other issue is that you don’t want to concatenate and call convert and other built-ins inside EXEC, how about:

    ALTER PROCEDURE [dbo].[sprocAddDatesSymbolsAndPeriodsToAggregatedStudy]
        @table   VARCHAR(120), 
        @maxDate DATE
    AS
    BEGIN
        SET NOCOUNT ON;
    
        DECLARE @sql NVARCHAR(MAX) = N';WITH t1 AS
        (
            SELECT Symbol, TradingDate
            FROM tblSymbolsMain
            CROSS JOIN tblTradingDays
            WHERE TradingDate <= ''' + CONVERT(CHAR(8), @maxDate, 112) +
        '''), 
        t2 AS
        (
            SELECT Symbol, TradingDate, Period
            FROM t1
            CROSS JOIN tblPeriods
        )
        INSERT INTO ' + @table + ' (Symbol, TradeDate, Period)
        (SELECT Symbol, TradingDate, Period
        FROM t2
        EXCEPT
            (SELECT t3.Symbol, t3.TradeDate, t3.Period
             FROM ' + @table + '))';
    
        EXEC sp_executesql @sql;
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a class from Linq to SQL Clasees with VS 2008 SP1 Framework
Made solution change: I am trying to display a html table of data.. In
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }
I made a code that translate strings to match each word from the array
I have a page with a menu that uses JQuery AJAX calls to populate
I noticed that I seemingly wasn't able to sort on relevance in a default
I'm somewhat new to OOP with C++, so I'm hoping that I've just made
I made this app that takes time entries from fogbugz and posts them to
I have two strings with seemingly the same values. One is stored as a
I made some seemingly harmless changes (added a few domain classes, added the plugin

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.