hey all i got a question where i am not sure that it will be possible.

i already have my table in my data base which has values in it ex: first_property. and i made a little script which helps me grab all the names in the form that i will be posting to the DB and puts it into a sql query.
ex:
ALTER TABLE `properties` ADD `first_property` TEXT NULL ,
ADD `second_property` TEXT NULL ,
etc
;

but i do have duplicates on different pages and i run into the error
#1060 - Duplicate column name 'first_property'

now the question: is there a syntax for sql to skip that name if it exist

thanks for any help.

Recommended Answers

All 4 Replies

hey all i got a question where i am not sure that it will be possible.

i already have my table in my data base which has values in it ex: first_property. and i made a little script which helps me grab all the names in the form that i will be posting to the DB and puts it into a sql query.
ex:
ALTER TABLE `properties` ADD `first_property` TEXT NULL ,
ADD `second_property` TEXT NULL ,
etc
;

but i do have duplicates on different pages and i run into the error
#1060 - Duplicate column name 'first_property'

now the question: is there a syntax for sql to skip that name if it exist

thanks for any help.

Hello,

you can use IF ELSE condition of Transact SQL

IF Boolean_expression 
     { sql_statement | statement_block } 
[ ELSE 
     { sql_statement | statement_block } ]

an example can be like the following;

DECLARE @compareprice money, @cost money 
EXECUTE Production.uspGetList '%Bikes%', 700, 
    @compareprice OUT, 
    @cost OUTPUT
IF @cost <= @compareprice 
BEGIN
    PRINT 'These products can be purchased for less than 
    $'+RTRIM(CAST(@compareprice AS varchar(20)))+'.'
END
ELSE
    PRINT 'The prices for all products in this category exceed 
    $'+ RTRIM(CAST(@compareprice AS varchar(20)))+'.'

Hope this will help you, find the Property name and match it with your new entries.... Hope this will help you.

whoa. i think that is a little different from what i needed. what i am doing is throwing the mysql query in to phpmyadmin directly.

from what i see there is it looks like that is calling from the DB. but i am not sure. that is a little beyond me what is going on there.

Member Avatar for diafol

Why do you need to create a new field? You seem to be adding a new field instead of a new record. Could you elaborate on the implementation?

Why do you need to create a new field? You seem to be adding a new field instead of a new record. Could you elaborate on the implementation?

np. what is going on is simple. i am just adding fields to a table that i am still building by using the alter table and add function. and i have multiple forms that push and pull data from the DB.

i made a little script which will put all the values from that form into the syntax for mysql. then i take it and just so to phpmyadmin and dump that data into the sql.

but i get that the name is a duplicate and was wondering if there was a way that i could make the query skip adding that value to the table if it already exist in the table

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.