When i run the below script i'm getting "TYPE MISMATCH" Error
'Getting error when i execute below code
query1 = "Select count(*) from test" & _
Query2 = query1 & "where proc_d" & _
Query3 = Query2 & "IN('10 jun 2015')"
The reason for your error is that
query1 = "Select count(*) from test" & _
Query2 = query1 & "where proc_d" & _
Query3 = Query2 & "IN('10 jun 2015')"
becomes
query1 = "Select count(*) from test" & Query2 = query1 & "where proc_d" & Query3 = Query2 & "IN('10 jun 2015')"
after combining lines together.
Change it to
query1 = "Select count(*) from test " & _
"where proc_d " & _
"IN('10 jun 2015')"
Note also the addition of the extra space after the words "test" and "proc_d". Without those spaces the SQL command will be constructed, but will be invalid.
Related
I'm using a VBA code in excel to pick some data and insert it into an Access DB. I need this for several tables.
The problem is: For some of those tables, I get an error like: "INSERT INTO syntax error". But, if I get the string the code generates and uses for inserting, and use it in SQL mode form Access, the query works just fine. So that doesn't make any sense. Here is a piece of it:
For j = 6 To lastrow
SQLStr = "INSERT INTO TENSILE(REFERENCE, REF_ID, POSITION, RATIO, YSL0, YSL90, YSL180, YSL270, YST0, YST90, YST180, YST270, UTSL0, UTSL90, UTSL180, UTSL270, UTST0, UTST90, UTST180, UTST270, EL0, EL90, EL180, EL270, ET0, ET90, ET180, ET270, ARL0, ARL90, ARL180, ARL270, ART0, ART90, ART180, ART270) SELECT '" & ws3.Cells(j, 1) & "', REF.ID,'" & ws3.Cells(j, 60).Value & "'"
For i = 61 To 93
SQLStr = SQLStr & "," & ws3.Cells(j, i).Value
Next i
SQLStr = SQLStr & " FROM REF WHERE REF.REFERENCE LIKE '" & ws3.Cells(j, 1) & "'"
ws3.Cells(7, 3).Value = SQLStr
MsgBox (SQLStr)
'rs.Open SQLStr, con, adOpenStatic, adLockOptimistic 'Opening the query
Next j
it's important to notice that this same structure is used for other tables and works normaly, like in:
For j = 6 To lastrow
SQLStr = "INSERT INTO METALOGRAPHY(REFERENCE, REF_ID, AUSTGRAINSIZE) SELECT '" & ws3.Cells(j, 1) & "',REF.ID ," & ws3.Cells(j, 18).Value & " FROM REF WHERE REF.REFERENCE LIKE '" & ws3.Cells(j, 1) & "'"
'MsgBox (SQLStr)
'ws3.Cells(2, 3).Value = SQLStr
rs.Open SQLStr, con, adOpenStatic, adLockOptimistic 'Opening the query
Next j
What is going wrong?
Have you considered changing how you are linked to the Access DB so that you could use a statement like:
db.execute SQLStr
This should solve your problem
I have a select statement which is running fine in sqlplus but when i m trying to run in Classic ASP code I am getting below error
ORA-01843: not a valid month
My Select Query is as below
SELECT YEAR_MONTH, LAST_DAY(TO_DATE(TO_DATE('201106','YYYYMM'),'MM/DD/YYYY')) AS MAX_END_DT FROM MONTH_DIM WHERE '04-28-2016' BETWEEN MONTH_START_DATE AND MONTH_END_DATE
ASP Code as Below
Dim rs
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT YEAR_MONTH, LAST_DAY(TO_DATE(TO_DATE('" & MAXYEARMONTH & "','YYYYMM'),'MM/DD/YYYY')) AS MAX_END_DT FROM MONTH_DIM WHERE '" & END_DT & "' BETWEEN MONTH_START_DATE AND MONTH_END_DATE"
set rs = cmd.execute --here is problem
use TO_DATE('" & END_DT & "','MM/DD/YYYY')
I am developing in ASP VBScript at work and need to run a SELECT DISTINCT query but I am having some troubles.
I have other queries in my code that work perfectly fine, that do not use SELECT DISTINCT.
Here is what I am using:
Dim sections()
c = 1
set conn=Server.CreateObject("ADODB.Connection")
set rs=Server.CreateObject("ADODB.Recordset")
conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=******;User ID=Admin;" & _
"DATA SOURCE=" & Server.MapPath("modules.mdb")
rs.open "SELECT DISTINCT section FROM modules WHERE area='First' ORDER BY lvl ASC",conn
ReDim sections(10)
do while not rs.EOF
sections(c) = rs("section")
c = c + 1
rs.MoveNext
loop
rs.Close
conn.Close
set rs = nothing
set conn = nothing
Which gives me this error:
error '80004005'
on the line of the SQL query
The only way to fix this is to use "GROUP BY" instead of "DISTINCT"
SELECT DISTINCT section FROM modules WHERE area='First' ORDER BY lvl ASC
SELECT section FROM modules WHERE area='First' GROUP BY section ORDER BY lvl ASC
im working on project which require crystal report 9 and vb6.
i created a crystal report page an selected all columns i want .
then in form user select the data by this code
If frmRepTabaee1.Check1.Value = 1 And frmRepTabaee1.chbTamin.Value = 1 Then
If frmRepTabaee1.txtTabai.Text = 1 Then
sqlStr = "select pcode,name,lastname,TTaminDarman1,y,mon from tbllisthogh" & frmRepTabaee1.txty & "" & frmRepTabaee1.txtmon & " where typepar= 'ÍÞæÞ' and idvoras = '0' order by convert(int,pcode )"
ElseIf frmRepTabaee1.txtTabai.Text = 2 Then
sqlStr = "select pcode,name,lastname,TTaminDarman2,y,mon from tbllisthogh" & frmRepTabaee1.txty & "" & frmRepTabaee1.txtmon & " where typepar= 'ÍÞæÞ' and idvoras = '0' order by convert(int,pcode )"
ElseIf frmRepTabaee1.txtTabai.Text = 3 Then
sqlStr = "select pcode,name,lastname,TTaminDarman3,y,mon from tbllisthogh" & frmRepTabaee1.txty & "" & frmRepTabaee1.txtmon & " where typepar= 'ÍÞæÞ' and idvoras = '0' order by convert(int,pcode )"
ElseIf frmRepTabaee1.txtTabai.Text = 4 Then
sqlStr = "select pcode,name,lastname,TTaminDarman4,y,mon from tbllisthogh" & frmRepTabaee1.txty & "" & frmRepTabaee1.txtmon & " where typepar= 'ÍÞæÞ' and idvoras = '0' order by convert(int,pcode )"
ElseIf frmRepTabaee1.txtTabai.Text = 5 Then
sqlStr = "select pcode,name,lastname,TTaminDarman5,y,mon from tbllisthogh" & frmRepTabaee1.txty & "" & frmRepTabaee1.txtmon & " where typepar= 'ÍÞæÞ' and idvoras = '0' order by convert(int,pcode )"
ElseIf frmRepTabaee1.txtTabai.Text = 6 Then
sqlStr = "select pcode,name,lastname,TTaminDarman6,y,mon from tbllisthogh" & frmRepTabaee1.txty & "" & frmRepTabaee1.txtmon & " where typepar= 'ÍÞæÞ' and idvoras = '0' order by convert(int,pcode )"
End If
End If
Screen.MousePointer = vbHourglass
rs.Open sqlStr, cn
Report.Database.SetDataSource rs, , 1
'--------------------------------
'''''''''''''''''''''''''''''''''
'''''''''''''''''''''
'-------------------
CRViewer91.Refresh
'-------------------
CRViewer91.ReportSource = Report
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
'End If
End Sub
Problem :
when sql query use diffrent columns to be select and that cuse the null problem in crystal report 9 , how can i set default value for null ?
in vb6& crystal report 9
thanks
I don't have version 9, but somewhere in Crystal Reports general settings for the report options you should have checkboxes for Convert Database NULL Values to Default and Convert Other NULL Values to Default. Checking those should eliminate your errors.
Can someone help me to convert from SQL Query to LINQ VB.NET:
select rls.* from Roles rls(nolock)
where rls.id not in (
select r.ID from usersRole ur (nolock)
inner join Roles r(nolock) on ur.RoleID = r.ID
where user_id = 'NY1772')
Thanks
i find my own answer...
'construct a where ID list
Dim lstRoleIDs = From ur In ctx.UsersRoles _
Join rl In ctx.Roles _
On ur.RoleID Equals rl.ID _
Where ur.User_ID = UserId _
Select rl.ID
Dim newQ = (From r In ctx.Roles _
Where Not lstRoleIDs.Contains( _
r.ID) _
Select New UserRoleList With {.ID = r.ID, .PermDesc = r.ID & " - " & r.Permission & " - " & r.PermissionDescription})
If you want to preserve the (NOLOCK) hints, I have blogged a handy solution using extension methods in C#. Note that this is the same as adding nolock hints to every table in the query.