moonraker12
asked on
How to insert minus sign (-) into column field
I know that this may be a simple question, but I am not too familiar with SQL and have not been able to find a solution. In a SQL 2005 Database table, I am trying to update a column field with a '-'.
As an example, I want to fill the column field 'code' with '12345-6789'. The problem is that when I attempt to do this, the SQL Query sees this as a request for the difference of the 2 numbers (12345 - 6789 = 5556), resulting in a field value of 5556.
Is there anyway to add the '-' into the column field, without having it subtract the values before and after it?
As an example, I want to fill the column field 'code' with '12345-6789'. The problem is that when I attempt to do this, the SQL Query sees this as a request for the difference of the 2 numbers (12345 - 6789 = 5556), resulting in a field value of 5556.
Is there anyway to add the '-' into the column field, without having it subtract the values before and after it?
select cast(1234 as varchar(4)) + '-' + cast(342 as varchar(3)) from tablename
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change your column datatype to varchar
update table_name
set code = col1 + '-' + col2
where <your_condiontion>
try this
set code = col1 + '-' + col2
where <your_condiontion>
try this
ASKER
angelIII,
That worked perfectly. I ran:
update table
set column = '12345-6789'
and got the desired outcome.
Thank you.
That worked perfectly. I ran:
update table
set column = '12345-6789'
and got the desired outcome.
Thank you.