I am using a single query:
(SELECT *,'{"Source": "010","Keys": [{"Value": "CHARGE"}]}' AS ID1
FROM DETAILS) metrics
JOIN DIM.TYPE trant
ON metrics.ID1 = trant.BK_TRANSACTIONTYPE
But I am getting this error:
SQL compilation error: syntax error line 3 at position 30 unexpected
'metrics'.
Please advise how it can be solved.
Can you please try with below query. Hope it works :)
SELECT * FROM (SELECT *,'{"Source": "010","Keys": [{"Value": "CHARGE"}]}' AS ID1 FROM DETAILS) metrics JOIN DIM.TYPE trant ON metrics.ID1 = trant.BK_TRANSACTIONTYPE
I am trying this query to fetch data from two table. I am getting the error on join.
select
bundlechecklist.Bundle_TXN_ID,
documentchecklist.Bundle_TXN_ID,
documentchecklist.Doc_Type_Name
from
bundle_checklist_txn bundlechecklist
outer join
Document_Checklist_TXN documentchecklist on
documentchecklist.Bundle_TXN_ID = bundlechecklist.Bundle_TXN_ID
where
bundlechecklist.originating_tran_id = "AMD1256" and bundle_name = "Line"
Please help me in fixing the error
I am currently constructing prepared statements and I am wondering how to use it in the WHERE part for LIKE and %. So I basically just want to SELECT the name from the database which is like the one that has been posted.
Here is my code:
$order = "SELECT name, name_id FROM requests WHERE name LIKE %?%" ;
$statement = $pdo->prepare($order);
$statement->bindParam(1, $_POST['name']);
$statement->execute();
$data = $statement->fetch(PDO::FETCH_ASSOC);
And here is the wonderful error that says that I use the wrong syntax with %:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[42000]: Syntax error or access violation: 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 '%'kevin'%' at line 1' in
/var/www/xxx/html/partials/requestinsert.php:13 Stack trace: #0
/var/www/xxx/html/partials/requestinsert.php(13): PDOStatement->execute() #1
/var/www/xxx/html/partials/requestcontact.php(231):
include('/var/www/xxx...') #2 /var/www/xxx/html/xxx.php(124):
include('/var/www/xxx...') #3 {main} thrown in
/var/www/xxx/html/partials/requestinsert.php on line 13
You need to supply query parameter when you bind the parameters like below:
$order = "SELECT name, name_id FROM requests WHERE name LIKE ?" ;
$var = "%" . $_POST['name'] . "%";
$statement->bindParam(1, $var);
I have some SQL which executes fine on mssql platform, but we I executes it from a switch yard camel flow (SQL-binding) it do not work.
The sql is
SELECT
p.ProductID,p.dtGTIN,p.ProductWeight
,p.dtPurchasePriceUnit,p.dtItemGroupID,
p.dtPromotionID,p.IntroductionDate,p.dtOnOrder,
p.dtExposureGroup,p.dtPlanogram,p.ProductHeight,
p.ProductWidth,p.ProductLength,p.dtPackageSize1,
p.productHeightUOMID,p.productWidthUOMID,p.productLengthUOMID,
pn.dtProductNameDescription1,pn.dtProductNameDescription2,
pv.VendorID,pr.ReferenceNumber
FROM ODS_Product p
JOIN ODS_ProductName pn
ON pn.ProductID=p.ProductID and pn.BusinessUnitId=p.BusinessUnitId
JOIN ODS_ProductVendor pv
ON pv.ProductID=p.ProductID and pv.BusinessUnitId=p.BusinessUnitId
LEFT JOIN ODS_dtProductReference pr
ON (pr.ProductID=p.ProductID and pr.BusinessUnitId=p.BusinessUnitId and
pr.ReferenceID='SRII')
where p.ProductID=# and p.BusinessUnitId=#
The message is
Caused by exception of type com.microsoft.sqlserver.jdbc.SQLServerException,
message: com.microsoft.sqlserver.jdbc.SQLServerException: The multi-part
identifier "p.ProductID" could not be bound.:
org.switchyard.HandlerException: org.switchyard.HandlerException:
org.springframework.jdbc.UncategorizedSQLException:
PreparedStatementCallback; uncategorized SQLException for SQL. SQL state
[null]; error code [0]; com.microsoft.sqlserver.jdbc.SQLServerException: The
multi-part identifier "p.ProductID" could not be bound.; nested exception is
com.microsoft.sqlserver.jdbc.SQLServerException:
com.microsoft.sqlserver.jdbc.SQLServerException: The multi-part identifier
"p.ProductID" could not be bound.
Any idea why?
as per my knowledge, you cannot use and in Join clause. please try by removing the and part from join statements.
SELECT
p.ProductID,p.dtGTIN,p.ProductWeight
,p.dtPurchasePriceUnit,p.dtItemGroupID,
p.dtPromotionID,p.IntroductionDate,p.dtOnOrder,
p.dtExposureGroup,p.dtPlanogram,p.ProductHeight,
p.ProductWidth,p.ProductLength,p.dtPackageSize1,
p.productHeightUOMID,p.productWidthUOMID,p.productLengthUOMID,
pn.dtProductNameDescription1,pn.dtProductNameDescription2,
pv.VendorID,pr.ReferenceNumber
FROM ODS_Product p
JOIN ODS_ProductName pn
ON pn.ProductID=p.ProductID
join ODS_ProductName pn1 pn1.BusinessUnitId=p.BusinessUnitId
JOIN ODS_ProductVendor pv
ON pv.ProductID=p.ProductID
JOIN ODS_ProductVendor Pv1 pv1.BusinessUnitId=p.BusinessUnitId
LEFT JOIN ODS_dtProductReference pr
where p.ProductID=# and p.BusinessUnitId=#
I am not sure, but it might help you.
Found a solution to it. The problem was the sql drivers prepared statement thingy. It could not interprete the "p.productId" for some reason, so when i removed all Aliases from the SQL it worked (But I dont know why):
SELECT ODS_Product.ProductID,ODS_Product.dtGTIN,ODS_Product.ProductWeight
,ODS_Product.dtPurchasePriceUnit,ODS_Product.dtItemGroupID,
ODS_Product.dtPromotionID,ODS_Product.IntroductionDate,
ODS_Product.dtOnOrder,ODS_Product.dtExposureGroup,ODS_Product.dtPlanogram,
ODS_Product.ProductHeight,ODS_Product.ProductWidth,
ODS_Product.ProductLength,ODS_Product.dtPackageSize1,
ODS_Product.productHeightUOMID,ODS_Product.productWidthUOMID,
ODS_Product.productLengthUOMID,ODS_ProductName.dtProductNameDescription1,
ODS_ProductName.dtProductNameDescription2,ODS_ProductVendor.VendorID,
ODS_dtProductReference.ReferenceNumber
FROM ODS_Product
JOIN ODS_ProductName ON ODS_ProductName.ProductID=ODS_Product.ProductID
and ODS_ProductName.BusinessUnitId=ODS_Product.BusinessUnitId
JOIN ODS_ProductVendor ON ODS_ProductVendor.ProductID=ODS_Product.ProductID
and ODS_ProductVendor.BusinessUnitId=ODS_Product.BusinessUnitId
LEFT JOIN ODS_dtProductReference ON
ODS_dtProductReference.ProductID=ODS_Product.ProductID
and ODS_dtProductReference.BusinessUnitId=ODS_Product.BusinessUnitId
and ODS_dtProductReference.ReferenceID='SRII')
where ODS_Product.ProductID='2602_1487130'
and ODS_Product.BusinessUnitId=6
You are mixing implicit joins with explicit joins. That is allowed, but you need to be aware of how to do that properly.
The thing is, explicit joins (the ones that are implemented using the JOIN keyword) take precedence over implicit ones (the 'comma' joins, where the join condition is specified in the WHERE clause).
http://www.neighborrow.com is currently displaying this error:
Warning (512): SQL Error: 1054: Unknown column 'User.rating' in 'order clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 527]
Where's the error in this query?
SELECT `User`.`id`, `User`.`first_name`, `User`.`last_name`, `User`.`email`,
`User`.`password`, `User`.`phone`, `User`.`address`, `User`.`city`, `User`.`zip`,
`User`.`region`, `User`.`verified`, `User`.`residence_id`, `User`.`rating_id`,
`User`.`facebook_id`, `Residence`.`id`, `Residence`.`residence` FROM `users` AS `User`
LEFT JOIN `residences` AS `Residence` ON (`User`.`residence_id` = `Residence`.`id`)
WHERE `User`.`first_name` IS NOT NULL ORDER BY `User`.`rating` DESC LIMIT 5
You don't have the column "rating" in your "User" table.
The "error" is at:
User::get_top() - APP/models/user.php, line 134
according to your site, at least that's where it's called from.