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

  • Home
  • SEARCH
  • 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 5839627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:36:39+00:00 2026-05-22T11:36:39+00:00

I am getting scalar variable not define @cmdSQL while trying to print my query

  • 0

I am getting scalar variable not define @cmdSQL
while trying to print my query to see what is d sql query is getting generating while running

print @cmdSQL = @cmdSQL + ' from server_des where title Like ''%'+@title+'%'' AND Description  Like ''%'+@Description+'%'' AND Keywords Like ''%'+@Keywords+'%'' AND category Like ''%'+@Category+'%'' AND Location Like ''%'+@Location+'%''AND source Like ''%'+@Source+'%'' AND Date Like ''%'+@Date+'%'

exec All_Searchnew1 'man','thief','ma','ma','ma','ma','12/12/2009',1,1,1,0,0,0,0,0

procedure Is written below...


Alter PROCEDURE [dbo].[All_Searchnew1]
@title nvarchar(max),
@Description nvarchar(max),
@Keywords nvarchar(max),
@Category nvarchar(max),
@Location nvarchar(max),
@Source nvarchar(max),
@Date nvarchar(50),
@RD_btn_AND_OR AS BIT,
@Chk_title AS BIT ,
@Chk_Description AS Bit ,
@Chk_Keywords AS BIT,
@Chk_Category AS BIT,
@Chk_Location AS BIT,
@Chk_Source AS BIT,
@Chk_Date AS BIT


AS

DECLARE @cmdSQL AS VARCHAR(2000) 
SET @cmdSQL = 'Select '

DECLARE @cmdCondition AS VARCHAR(2000) 
SET @cmdCondition = ''

if @RD_btn_AND_OR = 1
    Begin
    if (@Chk_title = 1)
          begin
          SET @cmdSQL = @cmdSQL + ' title,'
          SET @cmdCondition ='title Like ''%' + @title + '%'''
          end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as title'
        SET @cmdCondition ='title Like ''%' + @title + '%'''
        end

    if  @Chk_Description <> 1
        begin
        SET @cmdSQL = @cmdSQL + ' Description,'
        SET @cmdCondition ='Description Like ''%' + @Description + '%'''
        end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as Description'
        SET @cmdCondition ='Description Like ''%' + @Description + '%'''
        end

    if  @Chk_Keywords <> 1
        begin
        SET @cmdSQL = @cmdSQL + ' Keywords,'
        SET @cmdCondition ='Keywords Like ''%' + @Keywords + '%'''
        end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as Keywords'
        SET @cmdCondition ='Keywords Like ''%' + @Keywords + '%'''
        end
    if  @Chk_Category <> 1
        begin
        SET @cmdSQL = @cmdSQL + ' Category,'
        SET @cmdCondition ='Category Like ''%' + @Category + '%'''
        end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as Category'
        SET @cmdCondition ='Category Like ''%' + @Category + '%'''
        end
    if  @Chk_Location <> 1
        begin
        SET @cmdSQL = @cmdSQL + ' Location,'
        SET @cmdCondition ='Location Like ''%' + @Location + '%'''
        end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as Location'
        SET @cmdCondition ='Location Like ''%' + @Location + '%'''
        end
    if  @Chk_Source <> 1 
        begin
        SET @cmdSQL = @cmdSQL + ' Source,'
        SET @cmdCondition ='Source Like ''%' + @Source + '%'''
        end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as Source'
        SET @cmdCondition ='Source Like ''%' + @Source + '%'''
        end
    if  @Chk_Date <> 1 
        begin
        SET @cmdSQL = @cmdSQL + ' Date'
        SET @cmdCondition ='Date Like ''%' + @Date + '%'''
        end
    else
        begin
        SET @cmdSQL = @cmdSQL +'null as Date'
        SET @cmdCondition ='Date Like ''%' + @Date + '%'''
        end
End
--SET @cmdSQL = @cmdSQL + ' from server_des where title like ''%''' + @title + '''%'' AND Description  Like '''%''+@Description+''%''' AND Keywords Like '''%''+@Keywords+''%''' AND category Like '''%''+@Category+''%''' AND Location Like '''%''+@Location+''%'''AND source Like '''%''+@Source+''%''' AND Date Like '''%''+@Date+''%''
--SET @cmdSQL = @cmdSQL + ' from server_des where title Like ''%' + @title + '%''or description like ''%'+@Description+'%''or keywords like ''%'+@Keywords+'%''or category like ''%'+@Category+'%'''
SET @cmdCondition = @cmdCondition
SET @cmdSQL = @cmdSQL + ' from server_des where ' + @cmdCondition

EXEC(@cmdSQL)
go
  • 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-22T11:36:40+00:00Added an answer on May 22, 2026 at 11:36 am

    Also you missed commas in expressions like this:
    SET @cmdSQL = @cmdSQL +'null as title'
    It should be SET @cmdSQL = @cmdSQL +'null as title,'

    Missing something is common problem when combining dynamic SQL from many pieces. This work should be done very attentively.

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

Sidebar

Related Questions

Just getting started with Linq to SQL so forgive the newbie question. I'm trying
Getting this error while trying to erase the last element of a list. I
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Im getting a string (simplified) from the backend that should be : { menu:
Anyone getting this error when using the new free chart controls MS bought from
i have an SQL statement wherein i am trying to update the table on
After years of working OK, I'm suddenly getting this message when trying to start
Getting a background process ID is easy to do from the prompt by going:
Getting started with jquery and having trouble getting hello world type example going for
Without getting a degree in information retrieval, I'd like to know if there exists

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.