Query genus required

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Jericevich

    #1

    Query genus required

    In my code below the result returns two rows. This particular Tenant occupys
    2 Units. How do I join the two rows to give me "Unit1 and Unit4"

    ALTER PROCEDURE dbo.getUnitNumb ers
    @TenantID int,

    @UnitNumber varchar(50) OUTPUT

    as

    SELECT TOP (8) @UnitNumber = UnitNumber

    FROM Area

    WHERE (TenantID = @TenantID)

    ORDER BY UnitNumber


  • cwapshere@london.edu

    #2
    Re: Query genus required

    I don't think you can do that with a single SELECT query. It may be
    better to count the number of rows returned, and if it's more than one
    loop through them and concatenate the string yourself.

    Carol

    Ivan Jericevich wrote:
    In my code below the result returns two rows. This particular Tenant occupys
    2 Units. How do I join the two rows to give me "Unit1 and Unit4"
    >
    ALTER PROCEDURE dbo.getUnitNumb ers
    @TenantID int,
    >
    @UnitNumber varchar(50) OUTPUT
    >
    as
    >
    SELECT TOP (8) @UnitNumber = UnitNumber
    >
    FROM Area
    >
    WHERE (TenantID = @TenantID)
    >
    ORDER BY UnitNumber

    Comment

    • Ivan Jericevich

      #3
      Re: Query genus required

      Thanks Carol, I had the assumption it would be something like this. But I
      simply don't know how to ask it to just that.
      <cwapshere@lond on.eduwrote in message
      news:1167919868 .939547.295610@ s34g2000cwa.goo glegroups.com.. .
      >I don't think you can do that with a single SELECT query. It may be
      better to count the number of rows returned, and if it's more than one
      loop through them and concatenate the string yourself.
      >
      Carol
      >
      Ivan Jericevich wrote:
      >
      >In my code below the result returns two rows. This particular Tenant
      >occupys
      >2 Units. How do I join the two rows to give me "Unit1 and Unit4"
      >>
      >ALTER PROCEDURE dbo.getUnitNumb ers
      >@TenantID int,
      >>
      >@UnitNumber varchar(50) OUTPUT
      >>
      >as
      >>
      >SELECT TOP (8) @UnitNumber = UnitNumber
      >>
      >FROM Area
      >>
      >WHERE (TenantID = @TenantID)
      >>
      >ORDER BY UnitNumber
      >

      Comment

      • RobinS

        #4
        Re: Query genus required

        Try posting this to microsoft.publi c.sqlserver.pro gramming.
        I think they will know how to do this, and if it definitely
        can't be done, they'll tell you that, too. I'm assuming this
        is SQLServer? I would post the version you are using, as
        well as the DDL for creating the tables, or the table
        structures.

        Robin S.
        -----------------------------------
        "Ivan Jericevich" <ivan@oberon.co .zawrote in message
        news:%23tLEUIAM HHA.3552@TK2MSF TNGP03.phx.gbl. ..
        In my code below the result returns two rows. This particular Tenant
        occupys 2 Units. How do I join the two rows to give me "Unit1 and
        Unit4"
        >
        ALTER PROCEDURE dbo.getUnitNumb ers
        @TenantID int,
        >
        @UnitNumber varchar(50) OUTPUT
        >
        as
        >
        SELECT TOP (8) @UnitNumber = UnitNumber
        >
        FROM Area
        >
        WHERE (TenantID = @TenantID)
        >
        ORDER BY UnitNumber
        >
        >

        Comment

        Working...