Click here to Skip to main content
15,905,587 members

Comments by Member 13818387 (Top 9 by date)

Member 13818387 15-May-18 12:33pm View    
Select doesn't work when I deleted quotes on CHAR(10)

When I run my Update Statement I've got
#1064 - Something is wrong in your syntax obok 'FROM posts P
    INNER JOIN postmeta M ON P.ID=M.post_id
    WHERE M.meta_key ' w linii 3

Without quotes on CHARR(10) error is:
#1064 - Something is wrong in your syntax obok 'CHAR(10)))
    FROM posts P
    INNER JOIN postmeta M ON P.ID=M.post_id
    W' w linii 2
Member 13818387 14-May-18 12:56pm View    
I almost have what I need, thank you.
Please, help me change Select in Update
This query returns the values I need.
SELECT CONCAT( P.POST_CONTENT, GROUP_CONCAT(M.meta_value ORDER BY M.meta_id SEPARATOR 'CHAR(10)'))
    FROM posts P
    INNER JOIN postmeta M ON P.ID=M.post_id
    WHERE M.meta_key = 'wpcf-obrazek'
    GROUP BY P.ID

But how to do Update from that?
I wrote
UPDATE P, M
SET P.post_excerpt = CONCAT( P.POST_CONTENT, GROUP_CONCAT(M.meta_value ORDER BY M.meta_id SEPARATOR 'CHAR(10)'))
    FROM posts P
    INNER JOIN postmeta M ON P.ID=M.post_id
    WHERE M.meta_key = 'wpcf-obrazek'
    GROUP BY P.ID
\
but I have an error
Member 13818387 14-May-18 7:55am View    
When I replace this piece of code, I'll get a statement like this:
Hide   Copy Code
SELECT DISTINCT twr_kod, twr_nazwa, twr_numerkat, twr_koddostawcy, knt_kod, twr_iloscmin, twi_ilosc, twi_rezerwacje, twi_zamowienia, twi_dataFROM (    SELECT TwrI_TwrId, MAX(twi_data) AS twi_data     FROM XL.TwrIlosci    GROUP BY TwrI_TwrId) AS A    RIGHT JOIN XL.TwrIlosci AS B ON A.TwrI_TwrId = B.TwrI_TwrId AND A.twi_data = B.twi_data) AS TWI    INNER JOIN XL.TOWARY AS TWR ON TWR.Twr_TwrId = TWI.TwI_TwrId    INNER JOIN XL.Kontrahenci AS K ON TWR.twr_kntid = K.knt_kntid

At the end there is one additional parenthesis
Member 13818387 10-May-18 10:32am View    
Should it work on both 2008 and 2017?
I checked only on 2017 but I've got an syntax error.
Member 13818387 10-May-18 9:20am View    
Is it possible to convert this query so that it works on MS SQL 2008 R2 I have an error and read that OVER CLAUSE does NOT Support ORDER BY for aggregate functions in SQL2008R2 (only for ranking)