Select/Insert/Update a column with out a header

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newbtemple
    New Member
    • Feb 2008
    • 31

    Select/Insert/Update a column with out a header

    Hey all, i'm trying to add two columns and send them into a column field in another table.

    But, i'm getting an error saying that my column doesn't have a header. Any suggestions on how into insert query results that are teh result of computations? TIA
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Can you post what you have so far?

    -- CK

    Comment

    • newbtemple
      New Member
      • Feb 2008
      • 31

      #3
      Code:
       select e1.position + e2.position
        Into DP.dbo.CP
        from DP.dbo.excelDp e1, DP.dbo.excelDp e2
        where e1.char1 = e2.char1 and e1.char2 = e2.char2  and e1.account = 'xx5' and e2.account = 'xx3'
      Msg 1038, Level 15, State 5, Line 2
      An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.
      the code returns a column. The first column is the result of the arithmetic operation but has no column name. I found a solution in my application code but it takes one full iteration through the data. It's not a big deal but I think that this might be a scenario i'll come across again and would like to learn. The SQL algorithms are about a bajagaziillion times faster than what I code.

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        A column alias should solve your problem. Something like.


        Code:
        select e1.position + e2.position as NewColumnName
        Into DP.dbo.CP
        from DP.dbo.excelDp e1, DP.dbo.excelDp e2  where e1.char1 = e2.char1 and e1.char2 = e2.char2  and e1.account = 'xx5' and e2.account = 'xx3'
        Happy Coding!


        -- CK

        Comment

        • newbtemple
          New Member
          • Feb 2008
          • 31

          #5
          Brilliant. Thanks for the help!

          Comment

          Working...