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. Math expression as Column value as string in the Dynamic Sql

Math expression as Column value as string in the Dynamic Sql

Scheduled Pinned Locked Moved Database
databasehelp
8 Posts 3 Posters 1 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.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    Hi all, I am passing column names in dynamic sql like 'col1, col2, col3' + ', ''' + @reportId + '''', up to col3 all the columns are giving correct values, but the @reportId is a string which has value as '1-085' that's being converted into integers and giving me the value '-084'. I mean may its calculating the expression and returning the resultant value. But I want that string to be as it is, means I want that value as '1-085' instead of a calculated value ie -84, is there anyway to do it. Any help would be greatly helpful, thanks in advance. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

    L 1 Reply Last reply
    0
    • I indian143

      Hi all, I am passing column names in dynamic sql like 'col1, col2, col3' + ', ''' + @reportId + '''', up to col3 all the columns are giving correct values, but the @reportId is a string which has value as '1-085' that's being converted into integers and giving me the value '-084'. I mean may its calculating the expression and returning the resultant value. But I want that string to be as it is, means I want that value as '1-085' instead of a calculated value ie -84, is there anyway to do it. Any help would be greatly helpful, thanks in advance. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

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

      If it is a string then it will be saved as a string. Your code must be doing something strange.

      I 1 Reply Last reply
      0
      • L Lost User

        If it is a string then it will be saved as a string. Your code must be doing something strange.

        I Offline
        I Offline
        indian143
        wrote on last edited by
        #3

        No I am passing it as a string only from an ssis package variable which is of type string, I am appending both these strings as 'col1, col2, col3' + ', ''' + @reportId + '''' and passing it as nvarchar parameter into a stored procedure Exec [ETL].[PopulateStageTable] ?, ?, ?, ?, ?, ?, ? There are other Parameters but they are not giving any problem excel this, I checked even the execute sql too has this parameter defined as nvarchar and same thing in the Stored procedure too, nothing is converted to number or anything like that Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

        J 1 Reply Last reply
        0
        • I indian143

          No I am passing it as a string only from an ssis package variable which is of type string, I am appending both these strings as 'col1, col2, col3' + ', ''' + @reportId + '''' and passing it as nvarchar parameter into a stored procedure Exec [ETL].[PopulateStageTable] ?, ?, ?, ?, ?, ?, ? There are other Parameters but they are not giving any problem excel this, I checked even the execute sql too has this parameter defined as nvarchar and same thing in the Stored procedure too, nothing is converted to number or anything like that Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          Rephrasing what the previous response was suggesting (I believe.) You posted a line where @reportId is used. Nothing in that line would change the value of that. That line has nothing to do with the value in @reportId. At that point it already has the value you are seeing. Consequently you are doing something before that which causes it to have that value. You need to find that and correct it.

          L I 2 Replies Last reply
          0
          • J jschell

            Rephrasing what the previous response was suggesting (I believe.) You posted a line where @reportId is used. Nothing in that line would change the value of that. That line has nothing to do with the value in @reportId. At that point it already has the value you are seeing. Consequently you are doing something before that which causes it to have that value. You need to find that and correct it.

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

            To rectify you, this is not something you believe, but deduced. It sounds correct, hence the upvote.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

            1 Reply Last reply
            0
            • J jschell

              Rephrasing what the previous response was suggesting (I believe.) You posted a line where @reportId is used. Nothing in that line would change the value of that. That line has nothing to do with the value in @reportId. At that point it already has the value you are seeing. Consequently you are doing something before that which causes it to have that value. You need to find that and correct it.

              I Offline
              I Offline
              indian143
              wrote on last edited by
              #6

              I didn't quite get your answer, but some how its deducting the value and putting it there. If you can answer that's fine, but you are not able that's fine I just added one more step in Control flow which updates that Column with the correct value. But if you know it would be helpful for me. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

              J 1 Reply Last reply
              0
              • I indian143

                I didn't quite get your answer, but some how its deducting the value and putting it there. If you can answer that's fine, but you are not able that's fine I just added one more step in Control flow which updates that Column with the correct value. But if you know it would be helpful for me. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                indian143 wrote:

                but some how its deducting the value

                Computers are deterministic. They do what they do because some code explicitly to do it that way. Not sure how I can make it clearer. If you go to the store and open your wallet and expect it to have $20 and it doesn't do you continue to look at the wallet expecting the $20 to show up. Or do you think back where you were before the store to figure out where that money went? Same thing it true for this code. You posted a line where you use the reportId variable. At that point it already had a value. The computer doesn't give it a value at that point, because it already had one. There is code before that line that gives it a value. You must find that code, not the code that you are looking at (again the code you posted) and then figure out from that why it has the value that it does.

                I 1 Reply Last reply
                0
                • J jschell

                  indian143 wrote:

                  but some how its deducting the value

                  Computers are deterministic. They do what they do because some code explicitly to do it that way. Not sure how I can make it clearer. If you go to the store and open your wallet and expect it to have $20 and it doesn't do you continue to look at the wallet expecting the $20 to show up. Or do you think back where you were before the store to figure out where that money went? Same thing it true for this code. You posted a line where you use the reportId variable. At that point it already had a value. The computer doesn't give it a value at that point, because it already had one. There is code before that line that gives it a value. You must find that code, not the code that you are looking at (again the code you posted) and then figure out from that why it has the value that it does.

                  I Offline
                  I Offline
                  indian143
                  wrote on last edited by
                  #8

                  Ok Got it my friend thank you, I put an another sql task that just updates that Column value, so I think we are good now my friend. Thanks, Abdul Aleem "There is already enough hatred in the world lets spread love, compassion and affection."

                  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