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. problem with select within select

problem with select within select

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadmin
4 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
    wajans
    wrote on last edited by
    #1

    Hi I want to execute below query in ms-sql server 2000 but its giving errors. Can anybody help please.

    select * from ( select vRefTable from mainmenu where iMenuId=58 )
    where (select vFieldsName from TableField where iMenuId=58
    and bIsPrimary=1 and iTableFieldId=11) = 1

    Its showing below errors. your help is greatly appreciated.

    Server: Msg 156, Level 15, State 1, Line 2
    Incorrect syntax near the keyword 'where'.
    Server: Msg 170, Level 15, State 1, Line 3
    Line 3: Incorrect syntax near '='.

    Thanks Ansari

    B W A 3 Replies Last reply
    0
    • W wajans

      Hi I want to execute below query in ms-sql server 2000 but its giving errors. Can anybody help please.

      select * from ( select vRefTable from mainmenu where iMenuId=58 )
      where (select vFieldsName from TableField where iMenuId=58
      and bIsPrimary=1 and iTableFieldId=11) = 1

      Its showing below errors. your help is greatly appreciated.

      Server: Msg 156, Level 15, State 1, Line 2
      Incorrect syntax near the keyword 'where'.
      Server: Msg 170, Level 15, State 1, Line 3
      Line 3: Incorrect syntax near '='.

      Thanks Ansari

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Well, I am not sure what are you trying to say with that T-SQL code but I think your query looks like this: select * , ( select vRefTable from mainmenu where iMenuId=58 ) from TableField where vFieldsName iMenuId=58 and bIsPrimary=1 and iTableFieldId=11 For more help post more descriptive question.


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

      1 Reply Last reply
      0
      • W wajans

        Hi I want to execute below query in ms-sql server 2000 but its giving errors. Can anybody help please.

        select * from ( select vRefTable from mainmenu where iMenuId=58 )
        where (select vFieldsName from TableField where iMenuId=58
        and bIsPrimary=1 and iTableFieldId=11) = 1

        Its showing below errors. your help is greatly appreciated.

        Server: Msg 156, Level 15, State 1, Line 2
        Incorrect syntax near the keyword 'where'.
        Server: Msg 170, Level 15, State 1, Line 3
        Line 3: Incorrect syntax near '='.

        Thanks Ansari

        W Offline
        W Offline
        wajans
        wrote on last edited by
        #3

        Hi I have tried to analyse my requirement below.

        mainmenu--TableName
        iMenuId vRefTable----ColoumnNames
        58 news ---------Records

        TableField
        iMenuId bIsPrimary iTableFieldId vFieldsName
        58 1 11 iNewsId

        news

        iNewsId vTitle vUR
        1 news1 http://www.gmail.com

        I am storing tablenames in MainMenu in vRefTable coloumn and coloumn names in vFieldsName of TableFields table. I want to extract tablename from MainMenu whose iMenuId=58 and coloumn name from TableField table whose iMenuId=58 and bIsPrimary=1 and iTableFieldId=11 i.e iNewsId. After this I will be having both table name and coloumn name, using this I want to extract data based on the table name & coloumn name which I am having. Thanks again Ansari

        1 Reply Last reply
        0
        • W wajans

          Hi I want to execute below query in ms-sql server 2000 but its giving errors. Can anybody help please.

          select * from ( select vRefTable from mainmenu where iMenuId=58 )
          where (select vFieldsName from TableField where iMenuId=58
          and bIsPrimary=1 and iTableFieldId=11) = 1

          Its showing below errors. your help is greatly appreciated.

          Server: Msg 156, Level 15, State 1, Line 2
          Incorrect syntax near the keyword 'where'.
          Server: Msg 170, Level 15, State 1, Line 3
          Line 3: Incorrect syntax near '='.

          Thanks Ansari

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          Well, I'm not sure what you are trying to acheive, and in my opinion its a rubbish way of doing it, but your problem is (I think) that you need to alias you sub-selects.

          select *
          from ( select vRefTable from mainmenu where iMenuId=58 ) as a
          where (select vFieldsName from TableField where iMenuId=58and bIsPrimary=1 and iTableFieldId=11) as b = 1

          But I still think you should re-write it

          Bob Ashfield Consultants Ltd

          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