Error Number: 1064 Codigniter old version - codeigniter-3

Try to run this syntax on localhost is fine, but on hosting seem like old version of phpmysql
Error Number: 1064
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 'groups as c WHERE a.user_id=b.id AND a.group_id=' at line 2
SELECT
b.id,b.first_name,b.last_name,b.username,b.email,c.name,FROM_UNIXTIME(b.created_on)
as created_on,b.active FROM users_groups as a , users as b , groups as
c WHERE a.user_id=b.id AND a.group_id=c.id
Filename: models/Users_model.php
Line Number: 40
MODEL_FILE
function get_all_query()
{
$sql = "SELECT b.id,b.first_name,b.last_name,b.username,b.email,c.name,FROM_UNIXTIME(b.created_on) as created_on,b.active
FROM users_groups as a , users as b , groups as c
WHERE a.user_id=b.id
AND a.group_id=c.id";
return $this->db->query($sql)->result();
}
Please..

Related

Easytrieve Plus and Db2 - Read a file as input to matching against Db2 table

I am running a batch job that reads in a file in with a list of templates. I am trying to find an example since the one I was provided will not work. I have tried to find any example of reading in a file via EZTPA00. The JCL is correct, but I keep getting an error. Here's the basic code followed by the error I'm getting:
LIST ON
PARM SSID('DB2G')
FILE INFILE1 VB (133 6233)
IP-REC 01 133 A
TEMPLATE 01 015 A
FILE OUFILE1 FB (100 1000)
OP-REC 01 100 A
COMMUN_TRANS_ID 01 040 A
COMMUN_TEMPLATE_NO 42 015 A
DEFINE H-CNT W 13 N
SQL DECLARE C1 CURSOR FOR +
SELECT TRANSACTION, TEMPLATE +
FROM DB2.TEMPLATE_TABLE WHERE +
TEMPLATE = INFILE1:TEMPLATE
FETCH FROM INFILE1
IF EOF INFILE1
DISPLAY 'TEMPLATE ' TEMPLATE ' NOT RETURNED'
STOP
END-IF
CLOSE INFILE1
* INPUT SETUP
JOB INPUT(INFILE1) +
START 010-INIT +
FINISH 999-END
* START THE SQL
SQL OPEN C1
DO WHILE SQLCODE NE +100
SQL FETCH C1 +
INTO :WS-TMPLT, :WS-COMMID
IF SQLCODE NE 0
DISPLAY 'PF : ERROR : SQLCODE : ' SQLCODE
STOP
END-IF
13 SQL DECLARE C1 CURSOR FOR +
SELECT COMMUN_TRANS_ID, COMMUN_TEMPLATE_NO +
FROM VMUSIU.E_COMM_DLVY WHERE +
COMMUN_TEMPLATE_NO = INFILE1:TEMPLATE
13 *******B204 SQL - SQL ERROR, SQLCODE IS -104
13 *******B204 SQL - DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL "?". SOME SYMBOLS THAT MIGHT BE LEGAL
13 *******B204 SQL - ARE: AND * AT OR SELECTIVITY YEAR YEARS MONTH MONTHS DAY DAYS HOUR
13 *******B204 SQL - DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE
I have no idea what the "?" is. I tried using a fetch for infile1 but it said it was invalid. Everything I try gives me the same answer. I even tried using ws variables, but it still failed. Does someone have something that allows you to match db2 table info against a file?

Difference in CTE using SQLite3 and PostgreSQL

I'm practicing SQL in Jupyter Notebook. I use sqlaclhemy and psycopg2 libs for practicing PostgreSQL syntax (using ElephantSQL) and sqlite3 lib for local db.
I have a request:
sql = '''
with medium_credits as (
select t.credit_amount from german_credit t
where t.credit_amount > 1000 and t.credit_amount < 3000
group by t.credit_amount),
medium_credits_info as (
select * from german_credit t
where t.credit_amount in medium_credits)
select t.purpose, t.housing, count(1) as count
from medium_credits_info t
group by t.purpose, t.housing
'''
Running this request using pd.read_sql(sql,connection), where connection is object created with sqlite3 - it goes great.
When I try to try it in Postgres-like system using pd.read_sql(sql,engine), where engine is object created with sqlalchemy, it throws a ProgrammingError:
ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "medium_credits"
LINE 14: where t.credit_amount in medium_credits)
I guess, Postgres doesn't let you use values from CTE-created table directly this way.
Is there any option I could run this code without an error?
PS: local and elephantsql databases are identical
try this :
with medium_credits as (
select t.credit_amount from german_credit t
where t.credit_amount > 1000 and t.credit_amount < 3000
group by t.credit_amount),
medium_credits_info as (
SELECT *
FROM german_credit t
INNER JOIN medium_credits m
ON m.credit_amount = t.credit_amount)

PostgreSQL: Why does this join query throw a syntax error

I don't understand, why the following query produced an error. Whereas in other dbms (eg mysql) this sort of query is absolutely legal.
ERROR: Syntax error at the end of input
LINE 1: SELECT * FROM "addr_country" AS c JOIN "addr_state" AS s
^
SQL state: 42601
Character: 59
Adding an on-clause to the query makes it working:
SELECT * FROM "addr_country" AS c JOIN "addr_state" AS s
ON c."id" = s."country" AND s.id = 10
Due to this answer, MySQL makes a cross join out of a join w/o conditions

MySQL Workbench generate this error

Error Code: 1064. 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 'AS a LIMIT 0, 1000' at line 3
Query:
SELECT * FROM (
subject s INNER JOIN prerequisite p ON s.subject_code = p.subject_id)
AS a
I think what you want to do are derived tables
https://dev.mysql.com/doc/refman/5.6/en/derived-tables.html
SELECT * FROM (
select * from subject s INNER JOIN prerequisite p ON s.subject_code = p.subject_id)
AS a

Throw error in SQL Server 2008 R2

I'm working with SQL Server 2008 R2 and I have an stored procedure where I'm trying to throw errror
throw 50001, 'Couldnot process,Please verify Transaction ID and EmbossLine', 1
But the query doesn't get executed and throws error on 50001. It was working fine on SQL Server 2012. I think there is some issue with versions. Is there anyother way I can throw error in SQL Server 2008 R2?
This is my stored procedure:
Alter procedure [dbo].[spGetRedemption]
#pan varchar(19),
#transId bigint
AS
Begin
if EXISTS(select * from POS_Transactions where ID=#transId)
Begin
select
PT.ID, PT.TransactionDate, M.MerchantName1,
PT.TerminalID, PT.BatchNumber, PT.SequenceNumber, PT.PAN,
C.EmbossName, PT.TotalAmount, PT.CurrencyCode,
TT.TransactionType, PT.InvoiceNumber
from
POS_Transactions PT
inner join
Terminal T on T.TerminalID = PT.TerminalID
inner join
Merchant M on M.MerchantID = T.MerchantID
inner join
Card C on C.EmbossLine = PT.PAN
inner join
TransactionType TT on TT.TransactionTypeID = PT.TransactionTypeID
where
PT.ID = #transId
and PT.PAN = #pan
END
Else
Begin
throw 50001, 'Couldnot process,Please verify Transaction ID and EmbossLine', 1
END
End
Throw is not available in SQL Server 2008R2; it was first introduced in SQL Server 2012.
https://msdn.microsoft.com/en-us/library/ee677615(v=sql.110).aspx
The alternative would be to use Raiserror (note; only 1 E in the middle; it's not RaiseError).
From the above link, there are some differences between these methods:
RAISERROR statement
If a msg_id is passed to RAISERROR, the ID must be defined in sys.messages.
The msg_str parameter can contain printf formatting styles.
The severity parameter specifies the severity of the exception.
THROW statement
The error_number parameter does not have to be defined in sys.messages.
The message parameter does not accept printf style formatting.
There is no severity parameter. The exception severity is always set to 16.