Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with update query

Posted on 2007-03-23
5
Medium Priority
?
173 Views
Last Modified: 2010-03-20
Hello,

I have a particular field in a sql database that is text and I went to use it to log information.  So what I am asking is what is the syntax for adding lines to existing data in a field?  How would I write the update query to add text the the data in the existing field so it can appear as a log of events.  Thanks your help.
0
Comment
Question by:2326ac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18778580
what database?

most of the times:
UPDATE yourtable
  SET yourfield = yourfield & "new data"

the & could be + or ||  ... depends on the database type you are using.

note however that when really want to make a kind of "log", you should make each log entry 1 row in a log table.
0
 

Author Comment

by:2326ac
ID: 18779057
Thank you I have tried your suggestion - see below:  

I get an error at cmd,executeNonQuery

Invalid Opertator for data type.  Operator equals add, type equals text.

Dim cmd As New SqlCommand("Update tblReqMain set Status = 'Approved', LManComments = '" + StrCom + "', ProbCat = '" + strProbCat + "', AuthName = '" + LbUsername.Text + "', History = History + '*** Authorised by line manager' Where ReqID = " & StrID, New SqlConnection(strconn))

All fields are either Text or VarChar
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18779115
if the field is TEXT (so you are using SQL Server), that is the problem, as you CANNOT update TEXT/NTEXT fields like that. you have to use UPDATETEXT command to update that field (the other fields can be updated normally!)

as noted above, using this as "log" is a conceptual and practical BAD idea, you should not do it that way.

if you have SQL Server 2005, you could use a workaround by using VARCHAR(MAX) instead of TEXT, then the update will work that way. (using + instead of & )
0
 

Author Comment

by:2326ac
ID: 18779922
There will only be a max three actions in this log of about a few lines each.  Thank you all for your advice.  I have tried the suggestion of updatetext (see below) but I get a syntax error near the value of strcom

Dim cmd2 As New SqlCommand("UPDATETEXT tblReqMain.history '" + StrCom + "' WHERE ReqID = " & StrID, New SqlConnection(strconn))
        cmd2.Connection.Open()
        cmd2.ExecuteNonQuery()
        cmd2.Connection.Close()

Any advice would be great
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18780404
you did not read the sample in the documentation, did you?
http://msdn2.microsoft.com/en-us/library/aa260658(SQL.80).aspx
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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. …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

636 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