Results 1 to 3 of 3

Thread: query question

  1. #1
    Join Date
    Dec 2004
    Posts
    37

    query question

    Hi guys, I have created an update query something simple like:

    UPDATE tableName
    SET variable = anotherVariable
    WHERE aVariable=var

    I was wondering could I have made this an Insert query as when i have tried to make this an insert query?
    It seems to be having problems with the where part of the statement.

    Thanks in advance.

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Example:
    create table tests1 (id int, name varchar(10))
    go
    insert into tests1 select 1,'a'
    insert into tests1 select 2,'b'
    insert into tests1 select 3,'c'
    insert into tests1 select 4,'d'
    insert into tests1 select 5,'e'
    insert into tests1 select 6,'f'
    go
    update tests1 set name='x' where id=3
    go

    If using variable then...
    declare @variable1 int
    declare @variable2 varchar(10)
    set @variable1=3
    set @variable2='x'
    update tests1 set name=@variable2 where id=@variable1

  3. #3
    Join Date
    Feb 2003
    Posts
    1,048
    You can't modify existing data using an insert query, you can only add new data, hence the problem with the "Where" clause.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •