Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. string concadination in sql query

string concadination in sql query

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yesu prakash
    wrote on last edited by
    #1

    Hi, My query -- parameter of the procedure @abc int = null; declare @txt varchar(100); set @txt = 'select * from tablename where field1 = isnull(@fld,field1)' set @txt = replace(@txt,'@fld',@abc) exec(@txt) when @abc has any value then its work fine, when @abc is null then @txt show null how can i concatenate this string and execute it Thankyou Ypki

    B P R L 4 Replies Last reply
    0
    • Y yesu prakash

      Hi, My query -- parameter of the procedure @abc int = null; declare @txt varchar(100); set @txt = 'select * from tablename where field1 = isnull(@fld,field1)' set @txt = replace(@txt,'@fld',@abc) exec(@txt) when @abc has any value then its work fine, when @abc is null then @txt show null how can i concatenate this string and execute it Thankyou Ypki

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Initialize variable @abc with 0 value, not with NULL. e.g set @abc=0


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com

      modified on Wednesday, May 18, 2011 3:12 AM

      1 Reply Last reply
      0
      • Y yesu prakash

        Hi, My query -- parameter of the procedure @abc int = null; declare @txt varchar(100); set @txt = 'select * from tablename where field1 = isnull(@fld,field1)' set @txt = replace(@txt,'@fld',@abc) exec(@txt) when @abc has any value then its work fine, when @abc is null then @txt show null how can i concatenate this string and execute it Thankyou Ypki

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        A simple trick is to use COALESCE which returns you the first none null entry in a sequence of values, so you would replace the reference to @abc with COALESCE(@abc, '').

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        1 Reply Last reply
        0
        • Y yesu prakash

          Hi, My query -- parameter of the procedure @abc int = null; declare @txt varchar(100); set @txt = 'select * from tablename where field1 = isnull(@fld,field1)' set @txt = replace(@txt,'@fld',@abc) exec(@txt) when @abc has any value then its work fine, when @abc is null then @txt show null how can i concatenate this string and execute it Thankyou Ypki

          R Offline
          R Offline
          Ra one
          wrote on last edited by
          #4

          try, set @txt = replace(@txt,'@fld',isNull(@abc, 0)) take 0 or any other value if you find null value hope it helps:thumbsup:

          1 Reply Last reply
          0
          • Y yesu prakash

            Hi, My query -- parameter of the procedure @abc int = null; declare @txt varchar(100); set @txt = 'select * from tablename where field1 = isnull(@fld,field1)' set @txt = replace(@txt,'@fld',@abc) exec(@txt) when @abc has any value then its work fine, when @abc is null then @txt show null how can i concatenate this string and execute it Thankyou Ypki

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Any operation on null will yield null. Set the initial value of @abc to something other than null.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups