The SQL command is:
select int_col from super, superb where super.ts = superb.ts and super.int_tag = sup erb.int_tag;
and the result shows DB error: invalid operation: invalid column name.
However, I check the column name of my stable, there is no problem:
Can anyone tell what's wrong here? I don't think I have a syntax error in my SQL command
int_col in select int_col from super, superb where super.ts = superb.ts and super.int_tag = sup erb.int_tag; is meaningless because both of your super table have a column called int_col.
You should change your SQL command to:
select super.int_col from super, superb where super.ts = superb.ts and super.int_tag = sup erb.int_tag;
or
select superb.int_col from super, superb where super.ts = superb.ts and super.int_tag = sup erb.int_tag;
Related
My query used in an SSRS report:
SELECT DISTINCT
asm.AssemblyCode,
asm.AssemblyRestorationDesc,
asm.AssemblyUnit,
asm.AssemblyGuid,
(SELECT SUM(m.MarkerQuantity)
FROM Marker m
WHERE m.AssemblyGuid = asm.AssemblyGuid
AND m.MarkerExcludeFromScope = 'False'
AND m.ContractGuid IN (#Contract)
AND m.Deleted = 0) AS Quantity,
(SELECT SUM(smkr.MarkerQuantity)
FROM BaselineMarker smkr
WHERE smkr.AssemblyCode = asm.AssemblyCode
AND smkr.MarkerExcludeFromScope = 'False'
AND smkr.Deleted = 0) AS BaselineQuantity,
(SELECT SUM(sa.AllowanceQuantity)
FROM BaselineAllowance sa
WHERE sa.AssemblyCode = asm.AssemblyCode
AND sa.Deleted = 0) AS AllowanceQuantity
FROM
Assembly asm
WHERE
asm.Deleted = 0
ORDER BY
asm.AssemblyCode, asm.AssemblyRestorationDesc, asm.AssemblyUnit, asm.AssemblyGuid
Throws an odd error that isn't really making sense given that the report works if I select a single value for the #Contract parameter instead of multiple values, which tells me the parameter itself is set up fine. Also, if I set the parameter itself to a single value parameter instead of calling multiple values, it works fine too.
The report also works if I manually enter the GUIDs by replacing the line AND m.ContractGuid IN (#Contract) with:
AND m.ContractGuid IN ('60A38AD0-F24F-DF11-A19C-00111103CDB5', 'F8C018CA-A00C-4BB1-B920-D460786F6820')
Could the parameter not be returning a list in the correct format?
Nothing should be odd about the parameter. It's Name is Contract, its prompt is Contract, its data type is text, it allows multiple values, the values are taken from a simple query. The return value is the contract guid, and the return prompt is the contract name.
The error I get is:
An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for dataset 'RestorationSummary'.
(rsErrorExecutingCommand) Must declare the scalar variable
"#Contract". Incorrect syntax near the keyword 'AS'. Incorrect syntax
near the keyword 'AS'.
I have a query, and in SQL Server Management Studio (2008), it is working perfectly, but when I add a subreport to my report when the same query with dynamic params, I get two errors.
The first time the values that I set in the set default values like, for example 'A' is interpreted like a column name and showing
Invalid column name A
When I send a constant 'A' without parameter, no errors are shown.
This is my code:
select top 1
isnull( dtssegcabv.dscv_fecharecepcion, 0) as FechaRecepcion
from
CabVenta
join
dtssegcabv on CabVenta.cvescv_id = dtssegcabv.scv_id
where
CabVenta.cve_letra = {?cve_letra}
and CabVenta.cve_codpvt = {?cve_codpvt}
and CabVenta.cve_nro = {?cve_nro}
and CabVenta.cvetco_cod = {?cvetco_cod}
If I send no default values (let the dialog empty), the error is
Incorrect Syntax Near Keyword And
I repeat, the query in SQL Server is working fine. The datatypes are all varchar.
Thanks for your help and sorry for my bad English.
It was a quotes problem:
select top 1
isnull( dtssegcabv.dscv_fecharecepcion, 0) as FechaRecepcion
from
CabVenta
join
dtssegcabv on CabVenta.cvescv_id = dtssegcabv.scv_id
where
CabVenta.cve_letra = '{?cve_letra}'
and CabVenta.cve_codpvt = '{?cve_codpvt}'
and CabVenta.cve_nro = '{?cve_nro}'
and CabVenta.cvetco_cod = '{?cvetco_cod}'
Works Perfectly
I get following error message when trying to insert an object in the database:
com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException:
DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2,
TABLEID=19, COLNO=0, DRIVER=4.15.134
How can I retrieve the table/column name for which the error is thrown?
Apparently at the package level, DB2 only works with the IDs and not the names.
You can find them back using the following query:
SELECT C.TABSCHEMA, C.TABNAME, C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = 2
AND T.TABLEID = 19
AND C.COLNO = 0
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME
I'm trying to use groovy.sql.Sql to create databases in an MSSQL (Microsoft SQL Server) server. It seem like the prepared statement adds additional quotes around the last parameter breaking the query.
This test code:
import groovy.sql.Sql
import com.microsoft.sqlserver.jdbc.SQLServerDataSource
def host = 'myhost'
def port = '1433'
def database = 'mydatabasename'
def usernameName = 'myusername'
def password = 'mypassword'
def dataSource = new SQLServerDataSource()
dataSource.setURL("jdbc:sqlserver://$host:$port")
dataSource.setUser(username)
dataSource.setPassword(password)
def connection new Sql(dataSource)
connection.execute(
'IF EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE name = ?) DROP DATABASE ?',
[ databaseName, databaseName ]
)
Gives the error:
Failed to execute: IF EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE name = ?) DROP DATABASE ? because: Incorrect syntax near '#P1'.
How can I use prepared statements without having it add single quotes around parameter one (DROP DATABASE ? seem to be rewritten as DROP DATABASE '?') or can I write the query in a different way so that the added single quotes does not produce a syntax error?
I would also be fine with other frameworks, if anyone could give me a working example.
Can you try:
connection.execute(
"IF EXISTS (SELECT * FROM master.dbo.sysdatabases WHERE name = $databaseName) DROP DATABASE ${Sql.expand(databseName)}"
)
I've got a issue passing a string literal parameter to a SQL function using peewee's fn construct. I've got an object defined as:
class User(BaseModel):
computingID = CharField()
firstName = CharField()
lastName = CharField()
role = ForeignKeyField(Role)
lastLogin = DateTimeField()
class Meta:
database = database
I'm attempting to use the mySQL timestampdiff function in a select to get the number of days since the last login. The query should look something like this:
SELECT t1.`id`, t1.`computingID`, t1.`firstName`, t1.`lastName`, t1.`role_id`, t1.`lastLogin`, timestampdiff(day, t1.`lastLogin`, now()) AS daysSinceLastLogin FROM `user` AS t1
Here's the python peewee code I'm trying to use:
bob = User.select(User, fn.timestampdiff('day', User.lastLogin, fn.now()).alias('daysSinceLastLogin'))
result = bob[0].daysSinceLastLogin
But when I execute this code, I get an error:
ProgrammingError: (1064, u"You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near ''day', t1.lastLogin, now()) AS
daysSinceLastLogin FROM user AS t1' at line 1")
Judging from this message, it looks like the quote marks around the 'day' parameter are being retained in the SQL that peewee is generating. And mySQL doesn't like quotes around the parameter. I obviously can't leave off the quotes in the python code, so can someone tell me what I'm doing wrong please?
Update: I have my query working as intended by using the SQL() peewee command to add the DAY parameter, sans quote marks:
User.select(User, fn.timestampdiff(SQL('day'), User.lastLogin, fn.now()).alias('daysSinceLastLogin'))
But I'm not sure why I had to use SQL() in this situation. Am I missing anything, or is this the right answer?
Is there a reason you need to use an SQL function to do this?
In part because I'm not very comfortable with SQL functions, I would probably do something like this:
import datetime as dt
bob = user.get(User = "Bob") #or however you want to get the User instance
daysSinceLastLogin = (dt.datetime.now() - bob.lastLogin).days