What is the syntax for concatenating in cfquery with access db - sql

So, I've looked all over the web for this simple answer...and I can't find it.
I am trying to search an access DB via coldfusion query.
<cfquery name = "x" datasource = "cassupport_computers">
SELECT last, first, dept, location, purchasedate, (last + ' ' + first + ' ' + dept + ' ' + location + ' ' + purchasedate AS searchs)
FROM cas_computers
WHERE searchs like '%#form.searchfield#%'
</cfquery>
What am I doing wrong? x:

<cfquery name = "x" datasource = "cassupport_computers">
SELECT last, first, dept, location, purchasedate, last & ' ' & first & ' ' & dept & ' ' & location & ' ' & purchasedate AS searchs
FROM cas_computers
WHERE searchs like '%#form.searchfield#%'
</cfquery>

Related

GROUP_CONCAT() error in h2 [42001-214] , [42122-214]

i keep getting this error GROUP_CONCAT(""""[*],a.montant, a.type_avance,a.date_avance,
a.remark SEPARATOR '') as Avance [42001-214] ,and after
i removed GROUP_CONCAT to test the code i got the error:
Column "" not found; SQL statement [42122-214]
here is my code:
SELECT i.n_dossier , concat(\"<html>\",i.nom_prenom,\"<br></html>\")
,concat(\"<html>\",i.vehicule,\"<br></html>\"),i.prime_totale ,"
+ " i.date_effet , i.date_echean ,GROUP_CONCAT(\"<html>\",a.montant,"
+ " a.type_avance,a.date_avance,a.remark SEPARATOR \"<br>\") as Avance ,i.reste ,i.GSM,"
+ "i.observation ,\"</html>\" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = "
+ " a.n_dossier GROUP by i.n_dossier,i.date_dossier,i.anuller having i.anuller = ' active '
You must repalce
GROUP_CONCAT("<html>",a.montant, a.type_avance,a.date_avance,a.remark SEPARATOR "<br>")
with
GROUP_CONCAT(CONCAT("<html>",a.montant, a.type_avance,a.date_avance,a.remark) SEPARATOR "<br>")
GROUP_CONCAT needs to have 1 column, as you see in the samle CONCAT will do that.
I don't why you use single quorted ' active 'and doou

How to generate column with row number?

I'm trying to make an query that will generate column with unique row number generated incrementally. My table with data don't have any unique value.
I was trying to get Gustav script, but I only manage to get it return 1 in every row.
Public Function RowCounter( _
ByVal strKey As String, _
ByVal booReset As Boolean, _
Optional ByVal strGroupKey As String) _
As Long
' Builds consecutive RowIDs in select, append or create query
' with the possibility of automatic reset.
' Optionally a grouping key can be passed to reset the row count
' for every group key.
'
' Usage (typical select query):
' SELECT RowCounter(CStr([ID]),False) AS RowID, *
' FROM tblSomeTable
' WHERE (RowCounter(CStr([ID]),False) <> RowCounter("",True));
'
' Usage (with group key):
' SELECT RowCounter(CStr([ID]),False,CStr[GroupID])) AS RowID, *
' FROM tblSomeTable
' WHERE (RowCounter(CStr([ID]),False) <> RowCounter("",True));
'
' The Where statement resets the counter when the query is run
' and is needed for browsing a select query.
'
' Usage (typical append query, manual reset):
' 1. Reset counter manually:
' Call RowCounter(vbNullString, False)
' 2. Run query:
' INSERT INTO tblTemp ( RowID )
' SELECT RowCounter(CStr([ID]),False) AS RowID, *
' FROM tblSomeTable;
'
' Usage (typical append query, automatic reset):
' INSERT INTO tblTemp ( RowID )
' SELECT RowCounter(CStr([ID]),False) AS RowID, *
' FROM tblSomeTable
' WHERE (RowCounter("",True)=0);
'
' 2002-04-13. Cactus Data ApS. CPH
' 2002-09-09. Str() sometimes fails. Replaced with CStr().
' 2005-10-21. Str(col.Count + 1) reduced to col.Count + 1.
' 2008-02-27. Optional group parameter added.
' 2010-08-04. Corrected that group key missed first row in group.
Static col As New Collection
Static strGroup As String
On Error GoTo Err_RowCounter
If booReset = True Then
Set col = Nothing
ElseIf strGroup <> strGroupKey Then
Set col = Nothing
strGroup = strGroupKey
col.Add 1, strKey
Else
col.Add col.Count + 1, strKey
End If
RowCounter = col(strKey)
Exit_RowCounter:
Exit Function
Err_RowCounter:
Select Case Err
Case 457
' Key is present.
Resume Next
Case Else
' Some other error.
Resume Exit_RowCounter
End Select
End Function
Sql query that I'm trying to get working is like this:
SELECT RowCounter("Query1",False) AS RowID, *
FROM Query1
WHERE (RowCounter("Query1",False)<>RowCounter("",True));
What am I missing to get this to work?
You are passing a fixed string as the parameter - and this gets No. 1.
Use the ID of the records of the query, like:
SELECT RowCounter(CStr([ID]),False) AS RowID, *

CSQL code in vb6 for displaying data between two dates?

Set COUNTER_RS = New Recordset
COUNTER_RS.Open "Select * from TT_COUNTER where Trans_dt >'" + Format(mskFdate.Text, "mm-dd-yyyy") + "' and Trans_dt <='" + Format(mskTdate.Text, "mm-dd-yyyy") + "' and Receipt_No like 'A%' and Head_Details='MED' order by Receipt_No", db, adOpenStatic, adLockOptimistic
MEDI = 0
If COUNTER_RS.RecordCount > 0 Then
While COUNTER_RS.EOF = False
MEDI = Val(COUNTER_RS!Rate)
COUNTER_RS.MoveNext
Wend
End If
Cant find the correct amount between two dates, please help with the code?

SQL Syntax error in CREATE TABLE statement in MS Access VBA subroutine

I am working on a subroutine in Microsoft Access VBA. The intended purpose of my program is to create a new table called newTableName and then perform a join on the two tables tableName1 and tableName2. The result of this join should be stored in newTableName. From my research online, I am led to believe that I cannot create an empty table to store the joined data in. So, I have attempted to duplicate tablenName2 and store its data in newTableName until the join is performed.
However, I get the following error when I run my program:
Run-time error '-2147217900 (80040e14)':
Syntax error in CREATE TABLE statement.
From this line:
CurrentProject.Connection.Execute strNewTableQuery
Which was tested with user input resulting in this query:
CREATE TABLE [UNIX_lob] AS SELECT * FROM UNIX
Here is my code:
Option Compare Database
Public Sub JoinWithIIMMModule()
Dim sqlNewTableQuery As String
Dim sqlJoinQuery As String
Dim tableName1 As String
Dim tableName2 As String
Dim newTableName As String
Dim commonField As String
' Set the common field used to join the two tables '
commonField = "[code]"
' Set the tableName1 to be used in the join. '
tableName1 = "IIMM"
' Acquire name of table to be joined with table1 from the user'
tableName2 = InputBox("Enter name of the table which you would like to join with " + tableName1 + ":", _
"Table to split", "UNIX")
' Set the name of the new table where the joins will be stored.'
newTableName = "[" + tableName2 + "_lob]"
' Create newTableName, which is a duplicate of the tableName2 table.'
' This is where the joined data will reside.'
sqlNewTableQuery = "CREATE TABLE " + newTableName + " AS SELECT * FROM " + tableName2
Debug.Print sqlNewTableQuery
CurrentProject.Connection.Execute sqlNewTableQuery
' Join tableName1 and tableName2 on commonField, and store the joined data in newTableName'
sqlJoinQuery = "SELECT " + tableName1 + ".*, " + tableName2 + ".*" & _
"INTO " + newTableName & _
"FROM " + tableName1 & _
"INNER JOIN " + tableName2 & _
"ON " + tableName1 + "." + commonField + " = " + tableName2 + "." + commonField + ";"
Debug.Print sqlJoinQuery
CurrentDb.Execute sqlJoinQuery
End Sub
Does anybody know what might be causing this error?

I am getting this error while executing update query in visual studio 2012

Incorrect syntax near '='
my code is
"update staff_Tables
set emp_id='" + txtEmployeeID.Text + "' ,
emp_sal='" + txtEmpSal.Text + "',
emp_name='" + txtEmployeeName.Text + "',
emp_Deignation='" + txtDesignation.Text + "',
Gender='" + cboGender.Text + "',
contactno='" + txtContact.Text + "',
Address='" + rtbAddress.Text + "',
Joining_Date='" + txtjoindate.Text + "'
where txtid=" + txtid.Text, sqlcon.getCon());
First, you should never concatenate sql queries like this.
Your query is extremely vulnerable to Sql Injection attacks.
Always use either stored procedures or parameterized queries.
Second, did you try to debug? judging by the column names, Emp_Id, Emp_Sal and contactno are probably numeric data and not strings, therefor the ' surrounding the values is wrong.
Your query should look like this:
"update staff_Tables
set emp_id = #emp_id,
emp_sal = #emp_sal,
emp_name = #emp_name,
emp_Deignation = #emp_Deignation,
Gender = #Gender,
contactno = #contactno,
Address = #Address,
Joining_Date = #Joining_Date
where txtid = #txtid"
and you add the parameter to the SqlCommand.Parameters collection like this:
cmd.Parameters.Add("#emp_id, SqlDBType.Int).Value = txtEmployeeID.Text
You probably have a single quote in one of your .Text values, fix by doubling them up, example:
Address='" + Replace(rtbAddress.Text, "'", "''") + "' vb
Address='" + rtbAddress.Text.Replace("'", "''") + "' #c
But yes, you are open to sql injection with this method of updating database.