I am trying to create an sql query that adds a string to the end of the cell. Right now I have this.
$sql = "UPDATE table SET $column1= $column1 + $newstring1, $column2 = $column2 + $newstring2, $column3 = $column3 + $newstring3, WHERE username = $user_username";
The values of $newstring1, $newstring2, and $newstring3 are formatted like "155:2,"
The idea is to add delimiters to each entry so I can easily sort them later. Right now I'm getting a syntax error on my query, but I'm new to php. Is the error because when the database is empty, there is no original variable and therefore I need to INSERT INTO instead of UPDATE, or is the comma in the string itself creating the error and do I need to somehow concatenate it?
I'm more used to C# than PHP so I'm not sure the proper way to format that type of query.
Related
Access 2013 - Reference an Unbound text box on a Form
I am currently trying to use an unbound text box [Text161] on a Form name [DCM_Gap_Servers] to sort information through a table. I want the query that I created to be able to take the users input from [DCM_Gap_Servers]![Text161] as the field that is being sorted from the table names 'Server'.
This is the SQL I am using right now in the query:
SELECT * FROM Servers WHERE "Forms![DCM_Gap_Servers]![Text161]" IS NULL
** I have already Tried:
"Forms![DCM_Gap_Servers]![Text161]" ; (Forms![DCM_Gap_Servers]![Text161]); Forms.[DCM_Gap_Servers]![Text161]
This will work at any time if I replace the Text Box reference with the actual Field name I am using, but since there are hundreds of combinations of fields, I need the reference to work.
I have looked all over, and I can't seem to find the correct answer. I am willing to do it in VBA if needed, whatever it takes to get the filtering done correctly.
Thank You.
It is:
SELECT * FROM Servers WHERE Forms.[DCM_Gap_Servers].[Text161] IS NULL
but that will just select all records whenever your textbox is Null.
So it rather is:
SELECT * FROM Servers WHERE SomeField = Forms.[DCM_Gap_Servers].[Text161]
To use the form value as a field name, you must use concatenated SQL:
strSQL = "SELECT * FROM Servers WHERE " & Forms![DCM_Gap_Servers]![Text161].Value & " IS NULL"
This you might pass to the SQL property of an existing query object:
MyQueryDef.SQL = strSQL
Or:
Constant SQL As String = "SELECT * FROM Servers WHERE {0} IS NULL"
FieldName = Forms![DCM_Gap_Servers]![Text161].Value
MyQueryDef.SQL = Replace(strSQL, "{0}", FieldName)
Of course, take care the the field name isn't a zero length string.
I'm attempting to execute this SQL Update statement and it's not working. Does anyone know why ?
update dbo.EBSTable
set CommandField = replace(CommandField, '%APPL.mbm_aging_file', '%APPL.mbm_aging_file)')
where Command like '[%]APPL.mbm_aging_file'
Basically, I'm just trying to add a ")" to the end of the data appearing in the CommandField field where the value is %APPL.mbm_aging_file (The "%" actually appears in the data).
I discovered my where clause was inadequate (like me with SQL). It should read
update dbo.EBSTable set CommandField = replace(CommandField, '%APPL.mbm_aging_file', '%APPL.mbm_aging_file)') where Command like '%[%]APPL.mbm_aging_file%'
That statement worked.
update dbo.EBSTable
set CommandField = '%APPL.mbm_aging_file' + ')' -- or set CommandField = '%APPL.mbm_aging_file)'
where Command = '%APPL.mbm_aging_file'
You can do this, as you only need to add ) at the end only for this specific case.
I have successfully queried data data in Access based on a value passed from a single text box on a form, but is there any way to pass a comma-delimited list into an IN query, or something to that effect?
The goal would be to search on more than a single-value criteria.
You would need to dynamically create your SQL in code, then feed the resultant query into the row source parameter.
If the comma list is numbers (1,5,723) then you can do:
ssql = "select * from table where field IN(" + scommalist + ")"
If the list is text, you have to parse it and put quotes around each value.
I am trying to insert a string into a char(20) column in my SQL Server database.
I set the string to be equal to a value and then add it to a parameter
thisstring = "1914"
cmd.Parameters.AddWithValue("#code", thisstring)
However every time I try it ends up looking like this in the database
I need it to look like the 1913, 000000, 000001 ones.
When I try to pad the string with spaces
thisstring= thisstring.PadLeft(20, " ")
or
thisstring = " " & thisstring
I am getting
String or binary data would be truncated
even if the field wasn't 20 characters total
What am I doing wrong?
Edit*** here is the column in SQL Server
http://imgur.com/BbV6VQv
I am not absolutely sure, but I think the problem lies in the AddWithValue.
While convenient this method doesn't allow to specify the exact datatype to pass to the database engine and neither the size of the parameter. It pass always an nvarchar parameter for a C# UNICODE string.
I think you should try with the standard syntax used to build a parameter
Dim p = new SqlParameter("#code", SqlDbType.Char, 20)
p.Value = thisstring.PadLeft(20, " ")
See this very interesting article on MSDN
I want to insert a record using SQL and one of the fields needs to contain a carriage return, e.g.
Notes field:
Line 1
Line 2
End line
How would I code this SQL statement using VB
When you build the insert statement, you store it in a string somewhere. Add an escaped newline character into the string wherever you want the carrage returns to be.
A simple way to do that in VB would be:
Sql = Sql & vbCrLf
Using SQL code:
UPDATE MyTable
SET MyCol = MyCol + CHAR(13) + CHAR(10);