Without your schema (i'm to lazy to reverse engineer using var tables) this is going to be a bit difficult to be sure.
When placed into one variable, your sql looks to compile down to this
SELECT * into ##accountprofile FROM OPENQUERY([MYSERVER],'SELECT ACC,CUST FROM ACCOUNTTABLE AP WHERE ap.cust in (select cust_no from G.DBO.Clients)')
My best guess is that your SELECT statement beside [MYSERVER] has been placed in there as a string, instead it needs to look like
SELECT * into ##accountprofile FROM OPENQUERY([MYSERVER],(SELECT ACC,CUST FROM ACCOUNTTABLE AP WHERE ap.cust in (select cust_no from G.DBO.Clients)))
To achieve this you would do the following in your @accountprofile variable.
SET @accountprofile = 'SELECT * into ##accountprofile FROM OPENQUERY([MYSERVER], (' + @accountprofile2 + '))'
Should this not solve your problem then if you would like to provide some schema to use to run this query against along with the actual error message i'll be happy to take a look when i have time.