i'm trying to migrate a mysql view from mysql to sql server 2008, but there is a funcion called "group_concat" and i cant emulate it in sql server.
Here is the code
select
permiso.ID AS ID,replace(
group_concat(cuerpo_legal.descripcion, _utf8' ',
documento_legal.NUM_CUERPO_LEGAL, _utf8' / ',
documento_legal.ANNO_CUERPO_LEGAL separator ',')
,_utf8',', _utf8' ; ') AS cuerpo_legal
from
(((permiso
join permiso_doc_legal ON ((permiso_doc_legal.ID_PERMISO = permiso.ID)))
join documento_legal ON ((documento_legal.ID = permiso_doc_legal.ID_DOCUMENTO_LEGAL)))
join cuerpo_legal ON ((cuerpo_legal.id_cuerpo_legal = documento_legal.ID_CUERPO_LEGAL)))
group by permiso.ID
I've tried diferent ways and searched here in stackoverflow but none one works
Thanks!
Related
I keep getting a syntax error "WITH is not valid input in this position" for WITH RECURSIVE. I've seen a similar problem here, where people back in 2018 said MySQL will support CTE's in MySQL version 8. Some other sources also refer that CTE should work for MySQL since version 8.0. My current version is 8.0.27, however, I still can't use WITH RECURSIVE in MySQL Workbench.
The query I need to retrieve the family tree is:
WITH RECURSIVE family_path (individual_id, first_name, path) AS
(
SELECT individual_id, first_name, first_name as path
FROM individual
WHERE parent IS NULL
UNION ALL
SELECT c.individual_id, c.first_name, CONCAT(fp.path, ' > ', c.first_name)
FROM family_path AS fp JOIN individual AS c
ON fp.individual_id = c.parent
)
SELECT * FROM family_path
ORDER BY path;
Is there any way for me to solve this problem?
I am converting a Query from SQL Server to MySQL but I have a problem converting the sentence contains table , because it uses rank .
I´ve looked for a similar property but I didn´t find anything , here is my Query at SqlServer
SELECT KEY_TBL.RANK
FROM CATS
INNER JOIN containsTABLE (CATS,(COLOR,CITY),'ORANGE',1000) AS KEY_TBL ON RUP.ID = KEY_TBL.[KEY]
ORDER BY RANK
I am running the following mysql query:
SELECT
MAX(CONCAT('FY', weeks.fy, ' Q', weeks.q, 'W', weeks.wInQuarter)) AS `Fiscal Week`,
SUM(cb_arr.total) AS `Cloud Backup Service Total`
FROM
billing.customers c
JOIN
billing.date_fiscal_weeks weeks
LEFT JOIN
cloud_backup_service.arr_customers cb_arr
ON cb_arr.src_id = c.alias AND weeks.weekDate = cb_arr.weekDate
WHERE
weeks.weekDate>'2020-04-19'
GROUP BY
weeks.weekDate
However each time I run it I get different output:
Any idea what is the issue here?
Thanks,
SHmulik.
I have this query
select if(flow_peymankar_type.title = '' ,
flows.title, flow_peymankar_type.title) as title,
flows.minRow,
[flow_peymankar_type].id,
[flows].[file],
[flows].isMandetory
from flow_peymankar_type
inner join flows
on flows.id = flow_peymankar_type.flowsId
where [peymankarTypeId]=11
order by flow_peymankar_type.code desc
and it's working fine in mysql.
But now I have to migrate to sql server 2008,
but this query is a problem for me and I don't know how to change it for working in sql server. plz help
Unfortunately, IIF is only available in sql server 2012 and later. Use CASE instead:
SELECT CASE
WHEN flow_peymankar_type.title = '' THEN flows.title
ELSE flow_peymankar_type.title
END AS title
....
I've spent a few hours staring at this piece of code. Fresh eyes please!
Here is a shortened version of the query:
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
'FROM (`requests` c) JOIN `inventory` d ON `d`.`listing_seq_no` = `c' at line 7
SELECT DISTINCT `c`.`req_id`, `u`.`user_id`, `u`.`org_name`,
CONCAT_WS(' ', `l`.`strength`, `l`.`unit)` as dos, `c`.`quantity` AS quantity1,
(SELECT sum(quantity) from inventory d2
WHERE d2.listing_seq_no = c.listing_seq_no
) as inv_total,
FROM (`requests` c)
JOIN `inventory` d
ON `d`.`listing_seq_no` = `c`.`listing_seq_no`
JOIN `listings` l
ON `l`.`listing_seq_no` = `c`.`listing_seq_no`
EDIT: Original CodeIgniter Code snippet:
$this->db->select ( "c.req_id,
u.user_id,
u.org_name,
l.tradename as name,
CONCAT_WS(' ', l.strength, l.unit) as dos,
);
This:
CONCAT_WS(' ', `l`.`strength`, `l`.`unit)`
Should be:
CONCAT_WS(' ', `l`.`strength`, `l`.`unit`)
try removing the parens around (requests c)
It's an old question, but you can use:
$this->db->select("<your_select_portion>", FALSE);
to avoid the auto-quoting feature of the CI DB class. I am a fan of using MySQL functions on select statements with CI, and this usually fixes the problem (except when you start using the query-caching feature, but that's another story).