Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

sql query question

Options
  • 26-02-2007 1:57pm
    #1
    Registered Users Posts: 1,073 ✭✭✭


    hi guys
    hope ye all had a good wkd
    have a SQL query question here:

    5) Write the SQL script to determine how many years an employee has worked
    in the company (emp table)

    Select ename "Name", hiredate ,round((months_between(sysdate,hiredate))/12) "Years in company"
    From emp
    Where ename = ‘&Name’;


    see the last line there; Where ename = ‘&Name’;
    why is this lin eneeded, i mean wat does it do

    thanks for yer time
    ed


Comments

  • Registered Users Posts: 273 ✭✭stipey


    Seems like a homework question?


  • Registered Users Posts: 1,073 ✭✭✭eurotrotter


    its solution that the lecturer did out in the notes
    but i am looking at it now and cant figure out why this last line i snecessary


  • Registered Users Posts: 1,477 ✭✭✭azzeretti


    In any query you will always need a "hook" to pull the required data out, this usually comes from a WHERE clause. The query below is saying as follows:

    Go to the emp table and get me back the Name, Hiredate and Years In Company but to get this information look at the ename column and only pull back this information when ename is equal to &Name.

    I can only guess what the &Name is in this query. If I had to guess I would say this is a variable for you to fill in e.g Select * from emp where name ="Smith" would pull back everything in the table where Name is = Smith.

    Mind you, this depends on the SQL database you are using. Most transact SQL is similar, but not identical, so the &Name could mean something else in a propriatory DB. I'd assume its a variable though, unless & is a wildcard in this DB etc/


  • Closed Accounts Posts: 35 narcissism


    its a variable, usually populated by user input via a parameter.


  • Registered Users Posts: 37,485 ✭✭✭✭Khannie


    moving to programming....


  • Advertisement
Advertisement