locked
SQL help RRS feed

  • Question

  • User1170894607 posted

    Hello!

    I have run into a bit of a problem with my SQL.

    What I am trying to do is select values in the columns Fname and Sname and insert them in to the column Uname Where the selected empNo emp = empno.
    i'm hoping this will run through every entry in my table.

    my query so for looks like this...

    Select SRuser.Fname, SRuser.Sname As Myname, SRUser.EmpNo as Emp
    Insert Myname Into SRuser (Uname)
    Where EmpNo = Emp;

    when i run the query i get the following error...

    The select statement contains a reserved word or argument name that is mispelt or missing, or the punctuation is incorrect.


    If anyone could give me any pointers to how to do this I would greatly appreciate it!

    Thanks in advance,

    Iain

    Wednesday, July 25, 2012 8:19 AM

Answers

  • User-183374066 posted

    If you want to insert only Sname to Uname then use only following statement. Dont use insert/select etc with it

    UPDATE SRuser
    SET Uname = Sname

    if you want to insert Fname + Sname to Uname than use following statement only

    UPDATE SRuser
    SET
    Uname = Fname + Sname
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 25, 2012 9:51 AM

All replies

  • User-661350001 posted

    actually it should be a update statement i guess ?

    then it would be 

    update  SrUser set Uname =  Sname where empno = @Emp

    Wednesday, July 25, 2012 8:31 AM
  • User-183374066 posted

    Update query will do the trick for you

    UPDATE SRuser
    SET Uname = Sname



    Wednesday, July 25, 2012 8:45 AM
  • User1170894607 posted

    Hello,

    Thanks for replying!

    I tried 

    Select SRuser.Fname, SRuser.Sname As Myname, SRUser.EmpNo as Emp
    Update SrUser set Uname = Myname where empno = @Emp;

    But get the same error message as above!

    Wednesday, July 25, 2012 8:46 AM
  • User-183374066 posted

    If you want to insert only Sname to Uname then use only following statement. Dont use insert/select etc with it

    UPDATE SRuser
    SET Uname = Sname

    if you want to insert Fname + Sname to Uname than use following statement only

    UPDATE SRuser
    SET
    Uname = Fname + Sname
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 25, 2012 9:51 AM
  • User1170894607 posted
    Thanks I'll give that a go tomorrow when I'm working on the database again!
    Wednesday, July 25, 2012 2:52 PM
  • User1170894607 posted

    That got it going! thank you!!!

    Thursday, July 26, 2012 11:55 AM