I have a column in a table which has value
121Z000CH YY03+ W
is it possible using sybase query language to update this column only in the characters 14 to 2 using substring? i.e. i need to replace 03 with some other number say 05.
Currently i'm trying the below statement which is giving me syntax error. Please correct me in this.
update recordtable
set substring(recordtable.column,14,2) = '05'
you can use below query for the same -
update recordtable
set column = substring(recordtable.column,1,13)
||'05'||substring(recordtable.column,16)
Related
I'm using apex oracle and running into missing equal sign error on this simple update statement. Can someone please point out what's wrong with this query?
update product_t
set qty-onhand = 11000
where productid = 28
qty-onhand is column qty minus column onhand.
You need to 'escape' the column name (or just use a better column name, without a minus sign in it).
update product_t
set "qty-onhand" = 11000
where productid = 28
I have a varchar column which has data like ABCDE1, the first five characters will be alphanumeric.
I would like to add a hyphen for all records after fifth character
ABCDE-1
How can I achieve using an update script in SQL Server?
Use STUFF function
Select STUFF(varchar_col,5+1,0,'-')
From yourtable
To Update
Update yourtable Set varchar_col = STUFF(varchar_col,5+1,0,'-')
I am trying to update a table coulmn, the table has thousands of records.
Currently I am updating the table by running the following query manually for some of the records.
UPDATE MyTable
SET column = REPLACE(column, 'ABC', 'ABC9')
WHERE where column like ‘ABC%’
Now I am trying to generate a generic query to update the table by adding a letter '9' after the alphabets. Thanks for your help
Use PATINDEX and STUFF
Patindex - Helps you to identify the first occurrence of numeric character in the string
Stuff - Helps you to insert 9 before the first occurrence of numeric character in the string
UPDATE MyTable
SET column = stuff(column,patindex('%[0-9]%',column),0,'9')
I'm trying to update a column named dattime that is a date column (not a datetime column like the name would lead you to believe) in my table named pr-pre-a with the current date. I'm using SQL Server 2012 and when I use:
UPDATE pr-pre-a
SET [dattime] = getdate()
the getdate() is not bolded meaning it is not a recognized command, and when I try to run it, it tells me there is a syntax error. however when I use:
UPDATE pr-pre-a
SET [dattime] = current_timestamp
it is bolded, but it still says there is a syntax error. What do I need to change to get this to work?
May be you need to escape - in your table name using []
UPDATE [pr-pre-a]
SET [dattime] = getdate()
Have you tried wrapping your table name in []?
I don't think SQL Server likes hyphens in table names without the square brackets or double apostrophes.
I wanted to update 1 column from a table present in a database maintained in SQL 2008 R2.
The entire column contains same value of data type int and I want to change to different value of same int data type.
When do we use single apostrophe in SET statement & when to avoid or not use it?
UPDATE TABLENAME
SET COLUMNNAME = X
OR
UPDATE TABLENAME
SET COLUMNNAME = 'X'
Appreciate any suggestions/advise. Thanks.
In SQL, single quotes are used around string values. Other "values", like integers, references to other columns etc, should never be single quoted.