Solved

SQL problem

Posted on 2009-07-07
11
253 Views
Last Modified: 2012-05-07
Hello, I have this sql that updates a flag in the database but I am having a problem with file names that have commas in them. It's causing a problem in running the sql. How can I modify this code so that it looks at the entire file and negates commas.
UPDATE HRForms

	SET Form_Name = '#Evaluate("form.Form_Name" & ThisRow)#',

		Category_ID = '#Evaluate("form.Category_ID" & ThisRow)#',

		Form_File = '#Evaluate("form.Form_File" & ThisRow)#',

		Status = '#Evaluate("form.Status" & ThisRow)#'

		WHERE HRForm_ID = #Evaluate("form.HRForm_ID" & ThisRow)#

Open in new window

0
Comment
Question by:DancingFighterG
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 2

Assisted Solution

by:shoppedude
shoppedude earned 100 total points
ID: 24797631
Try using the REPLACE function on the necessary fields, like this:

-Lee
UPDATE HRForms

	SET Form_Name = replace('#Evaluate("form.Form_Name" & ThisRow)#', ',', ''),

		Category_ID = '#Evaluate("form.Category_ID" & ThisRow)#',

		Form_File = replace('#Evaluate("form.Form_File" & ThisRow)#', ',', ''),

		Status = '#Evaluate("form.Status" & ThisRow)#'

		WHERE HRForm_ID = #Evaluate("form.HRForm_ID" & ThisRow)#

Open in new window

0
 

Author Comment

by:DancingFighterG
ID: 24798790
Still giviing me the same error:

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 2: Incorrect syntax near 's'.


SQL = "UPDATE HRForms SET Form_Name = replace('Employee's', ',', ''), Category_ID = '18', Form_File = replace('Employee's.xls', ',', ''), Status = '1' WHERE HRForm_ID = 277"

0
 
LVL 3

Expert Comment

by:QuinnDester
ID: 24798811
its the apostrophie in employees that is causing your problem, try replacing that as well
0
 

Author Comment

by:DancingFighterG
ID: 24798832
Yhea, that's what I'm trying to get rid of. Trying how to get rid of the apostrophie
0
 
LVL 2

Expert Comment

by:shoppedude
ID: 24799435
Within what application is this code being used?  I'm researching the #evaluate function and not finding much on it.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Accepted Solution

by:
QuinnDester earned 300 total points
ID: 24799459
if its in the database try this to clean it up
update table_name
set column_name = replace(column_name, '''','')
where column_name like '%''%'
that should remove them everywhere they exist in that column

if this is out side the database you need to clean it out before you can use it in a query, clean your string in the page code first
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 100 total points
ID: 24803510
replace(replace('#Evaluate("form.Form_Name" & ThisRow)#', ',', ''),chr(39),'')
0
 

Author Comment

by:DancingFighterG
ID: 24806045
This is what I have now:

UPDATE HRForms
      SET Form_Name = replace(replace('#Evaluate("form.Form_Name" & ThisRow)#', ',', ''),chr(39),''),
            Category_ID = '#Evaluate("form.Category_ID" & ThisRow)#',
            Form_File = replace(replace('#Evaluate("form.Form_Name" & ThisRow)#', ',', ''),chr(39),''),
            Status = '#Evaluate("form.Status" & ThisRow)#'
            WHERE HRForm_ID = #Evaluate("form.HRForm_ID" & ThisRow)#

Caused an error. Will try the update clean now!!
0
 
LVL 32

Expert Comment

by:awking00
ID: 24806255
Sorry, Oracle uses chr(), but I think T-SQL uses char(). Change the chr(39) to char(39) and re-try.
0
 

Author Comment

by:DancingFighterG
ID: 24806347
Ok, this is what I did:

UPDATE HRForms
    SET Form_Name = REPLACE(Form_Name, '''', '')
    WHERE (Form_Name LIKE '%''%')
    UPDATE    HRForms
    SET Form_File = REPLACE(Form_File, '''', '')
    WHERE     (Form_File LIKE '%''%')
      update HRForms
      set Form_File = replace(Form_File, '''','')
            where Form_File like '%''%'

Worked just fine so that when they upload a file it takes the ' out after the insert!! Thanks guys!!
0
 
LVL 32

Expert Comment

by:awking00
ID: 24806407
I think you could have also used the char() function like replace(form_name,char(39),''), but '''' is just as good. It's just that I never remember whether or not to use three or four single quotes to do the escape. :-) Glad you got it figured out.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now