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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:52:10+00:00 2026-05-25T22:52:10+00:00

Having an issue concatenating the following statement. Basically I want the length column to

  • 0

Having an issue concatenating the following statement.

Basically I want the length column to add inches after but it will not run. I am going to create a function out of this in the future but unable to get past this step. What gives?

declare @column varchar(255)
declare @sql varchar(5000)
declare @additional varchar(500)

set @column = 'length'

set @additional = 'inches'

select @sql = 'select distinct ps.p_c_id, '

select @sql = @sql +  @column + ' '+@additional+ ' ' + ' as value'

select @sql = @sql

select @sql = @sql + ' from dbo.Product ps
inner join dbo.ProductAttributes psa on psa.p_s_id = ps.p_s_id
where ps.p_c_id is not null and ' + @column + ' is not null'


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-05-25T22:52:10+00:00Added an answer on May 25, 2026 at 10:52 pm

    You are concatenating, what i’m assuming is an int or float value to a string ‘ inches’…have to cast the “length” value as a varchar…
    just select your @sql next time to see the resulting syntax and it should jump out at you. here is changes that should work
    BTW…look at implementing EXEC sp_executesql …makes dynamic sql less suseptable to injection by using parameters, etc… look up in Books OnLine
    Sorry…eating Crow…sp_executesql does not protect from injection just improves performance in general…see article MSDN SQL Injection

    declare @column varchar(255) 
    declare @sql varchar(5000) 
    declare @additional varchar(500) 
    
    set @column = 'psa.length' 
    
    set @additional = 'inches' 
    
    select @sql = 'select distinct ps.p_c_id, ' 
    
    select @sql = @sql + 'CAST(' + @column + ' AS varchar(10)) + ' + ''' '+@additional+ ''' ' + ' as value' 
    
    select @sql = @sql 
    
    select @sql = @sql + ' from dbo.Product ps 
    inner join dbo.ProductAttributes psa on psa.p_s_id = ps.p_s_id 
    where ps.p_c_id is not null and ' + @column + ' is not null' 
    
    --select @sql AS [ExecutableSQL]
    exec(@sql)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following Railscasts Episode #165 Edit Multiple but having issue where when I go
Having an issue here that I have tried everything I can think of but
Having an issue with traversing in jQuery.. hopfully an easy one..but I'm banging my
I am having issue with memory after running many times my app. java.lang.OutOfMemoryError: bitmap
i'm trying to create an application using three20 but i'm having issue to set
I have a primefaces dataList within a primefaces dataGrid but I'm having issue mapping
Having an issue with this particular method and not sure how to resolve it!
I having issue that content assistant / intellisense is working in methods such as
i am having issue with loading my selector via a jquery ajax load call
In analysis of energy demand and consumption data, I'm having issue re-sampling and interpolating

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.