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. T-SQL Problem

T-SQL Problem

Scheduled Pinned Locked Moved Database
sharepointdatabasehelpquestion
3 Posts 3 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.
  • W Offline
    W Offline
    WDI
    wrote on last edited by
    #1

    Hi I have a select statement that returns (A int ,B int) and another select statement that returns (C int , D int) in a storedprocedure. I need that sp returns a resultset as (A,B,C,D); What should i do plz?

    M S 2 Replies Last reply
    0
    • W WDI

      Hi I have a select statement that returns (A int ,B int) and another select statement that returns (C int , D int) in a storedprocedure. I need that sp returns a resultset as (A,B,C,D); What should i do plz?

      M Offline
      M Offline
      miah alom
      wrote on last edited by
      #2

      You can combine the two queries as following, select Select1.A, Select1.B, Select2.C, Select2.D from (select A, B from Table1) as Select1, (select C, D from Table2) as Select2 Please note that this will give you the cross product.

      1 Reply Last reply
      0
      • W WDI

        Hi I have a select statement that returns (A int ,B int) and another select statement that returns (C int , D int) in a storedprocedure. I need that sp returns a resultset as (A,B,C,D); What should i do plz?

        S Offline
        S Offline
        Shawn_H
        wrote on last edited by
        #3

        if they are scalar values you are dealing with then just do this. declare @a int, @b int, @c int, @d int select @a = 1, @b= 2 select @c = 3, @d= 4 select @a as ColA, @b as ColB, @c as ColC, @d as ColD Else, if it is a rowset, then do what alam_pune said, but pull a join column from each of the sub selects in order to join the rowsets to avoid the cartesian product select Select1.A, Select1.B, Select2.C, Select2.D from (select A, B, PriKeyCol from Table1) as Select1 inner join (select C, D, ForKeyCol from Table2) as Select2 on select1.PriKeyCol = select2.ForKeyCol

        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