effectively
Code:
update mytable
set mycolumn = left(mycolumn,len(mycolumn)-1
where right(mycolumn,1) = ">";
and
Code:
UPDATE [ONE BIG TABLE]
SET [ONE BIG TABLE].category_name = IIf(Right([category_name],1)=">",Left([category_name],Len([category_name])-1),[category_name]);
are the same. for the purists that last statement has probably got their blood pressure up a few notches
they do the same thing in a different way
both are seeking to rremove a trailing >
Code:
update mytable
set mycolumn = left(mycolumn,len(mycolumn)-1
where right(mycolumn,1) = ">";
uses three elements
1) update mytable
- tells the SQL engine we are trying to change values
2) set mycolumn = left(mycolumn,len(mycolumn)-1
- says replace the current value of mycolumn with everything in mycolumn less one character
3) where right(mycolumn,1) = ">";
- limits the rows to be processed by saying only include those rows who's rightmost character is = ">"
your version does the same thing but in a different way
Code:
UPDATE [ONE BIG TABLE]
SET [ONE BIG TABLE].category_name = IIf(Right([category_name],1)=">",Left([category_name],Len([category_name])-1),[category_name]);
the difference is that you are changing every value, using the IIF function you will always return a value, one where the preceding statement is true the other where it is false.
you don't need to encapusalte table or column names unless they have a space in them. you've created a rod for your back by calling your table ONE BIG TABLE so that must be referred to as [ONE BIG TABLE], but you do not need to refer to your columns as [category_name], category_name will do fine
the difference between the two queries is that one uses a where clause to limit the rows processed, the other doesn't, one only requests changes where a condition is satisfied, the other attempts to make changes to every row. granted the way SQL engines actually interpret that request depends on the SQL engine. some examine requested changes and do nothing if the resultant value would be the same as the proposed new value
every time you see a sentance starting with
select, eg select category_name from [one big table]
update, eg update [one big table] set category_name = "<a value>"
delete, eg delete * from [one big table]
..then its almost certainly a fragement of SQL
usually you will have to replace the suggested names of tabels and or columns with the names of your tables/columns. each contributor has their own style
some type the SQL bits in uppercase, eg SELECT my, comma, separated, column, list FROM mytable
some use italics for the stuff you need to replace, eg SELECT
my, comma, separated, column, list FROM
mytable
I tend to use mysomething to indicate where you should replace
eg
Code:
update mytable
set mycolumn = left(mycolumn,len(mycolumn)-1
where right(mycolumn,1) = ">";
so for you in this problem
mytable would be replaced with [one big table]
mycolumn would be replaced with category_name