Re: update column failure: Why?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 11/19/04


Date: Sat, 20 Nov 2004 00:44:29 +0100

On Fri, 19 Nov 2004 17:35:41 -0600, JPM wrote:

>Hi,
>
>SQL 2000
>Attempting to do a mass update to a single column in a table using the
>following sql via the query analyzer.
>
>UPDATE table1
>SET table1.Activity_Flag = Left(table1.Activity_Flag, 1)
>
>The column accepts NULL values and is char(2). The above sql indicates that
>it executes but a check of the data indicates that the space at the end of
>the field is still there. i.e. there are 2 characters in the field
>currently; I want to get rid of the space. What is wrong with this
>elementary sql?
>
>Thanks,
>JPM

Hi JPM,

If the columns is declared as CHAR(2), it is fixed length. The string
stored in it will always be two positions. If you give it just one
position, SQL Server will pad it with a space.

If you need to trim the space, you should use a VARCHAR(2) column. But may
I ask why this extra space is bothering you? There might be other (maybe
even better) ways to achieve what you want to get done.

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages

  • Re: SP - output parameter not coming back
    ... > Also I have tested the SP using SQL Query Analyzer and it does not ... If it does not work in query analyzer, it has no chance of working in asp ... > If I do not find out about the output parameter I am considering ... You definitely need to work on the stored procedure so that you can see the ...
    (microsoft.public.inetserver.asp.db)
  • Re: Missing table
    ... execute the commands within Query Analyzer. ... The first piece of sql displays the table owner, type, and the name of the table. ...
    (microsoft.public.sqlserver.server)
  • Re: Cannot edit table data using Enterprise Manager
    ... The point of using Query Analyzer is that you write the ... they could have had the SQL written and been done with it! ... change or insert some words to data string using Replace function is ... Manager wasn't designed to be a data entry tool. ...
    (microsoft.public.sqlserver.tools)
  • Re: performace issue with a stored procedure
    ... in Query Analyzer and look at the results in SQL Profiler. ... The high CPU you are seeing might be due to cursors or some bad SQL choices. ...
    (microsoft.public.sqlserver.programming)
  • Re: Local SQL Queries slow on Dual CPU/hyperthreading hardware
    ... This will tell if the problem is related to the SQL script you send or not. ... anti-virus, network monitoring, etc running? ... but only when hyperthreading is switched on using the same> physical hardware. ... In fact you don't need to run the query at all -> simply parsing it in SQL query analyzer is enough. ...
    (microsoft.public.sqlserver.server)