String Query Help

  • I have a task in hand wherein I can user only two variables (variable A and B) and one select statement.. If the input for variable A is given as 1 then Variable B should get an output from two tables. If Variable B is given as 2 then the variable B should get an output from two other tables.. But only single select statement should be used across the query.. Please help..

  • I would strongly recommend you don't. While a query like that is possible, it's an almost guaranteed performance problem, it'll also be hard to maintain and difficult to understand.

    Why aren't two SQL statements allowed? Really odd restriction.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks for the reply.

    I've achieved the same with the help of 2 select statements but not able to do so with one select statement in a string query.. My friend has already achieved it but has not shared with me on how he did.

  • There are ways to do it, but they're complex, harder to read and usually perform badly, hence why I'm recommending you use two statements. Production code isn't where you show clever, convoluted ways of doing things.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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