Only one expression can be specified in the select list error

  • I get the error "Only one expession can be satisifed in the select list when the subquery is not introduced with EXISTS.

    I know I'm not seeing something

    IF (select * from [tpqaplantsql\plantdb].LoggerReport.dbo.logger2)=0

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    ELSE

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    where id > (Select logkey from [tpqaplantsql\plantdb].LoggerReport.dbo.loggerstart)

  • IF (select * from [tpqaplantsql\plantdb].LoggerReport.dbo.logger2)=0

    Should that have "count" in the select?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • you want to test IF EXISTS(any rows in logger2)

    not that (somequery = 0)--you weanted to count the rows or something, right?

    so you'd want to tweak it to something like this:

    IF EXISTS(select * from [tpqaplantsql\plantdb].LoggerReport.dbo.logger2)

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    ELSE

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    where id > (Select logkey from [tpqaplantsql\plantdb].LoggerReport.dbo.loggerstart)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (2/20/2009)


    you want to test IF EXISTS(any rows in logger2)

    not that (somequery = 0)--you weanted to count the rows or something, right?

    so you'd want to tweak it to something like this:

    IF EXISTS(select * from [tpqaplantsql\plantdb].LoggerReport.dbo.logger2)

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    ELSE

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    where id > (Select logkey from [tpqaplantsql\plantdb].LoggerReport.dbo.loggerstart)

    You also need to change the "where" clause

    IF EXISTS(select * from [tpqaplantsql\plantdb].LoggerReport.dbo.logger2)

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    ELSE

    select * from [tpqa2appclstr\qa2appdb].Logger.dbo.logger2

    where id > (Select MAX(logkey) from [tpqaplantsql\plantdb].LoggerReport.dbo.loggerstart)


    * Noel

  • THANKS !!! Everyone...!

    That did the trick

    Good karma to you all.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply