Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do inside quotes
Message
De
10/09/2013 18:41:04
 
 
À
10/09/2013 18:09:28
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01582787
Message ID:
01582795
Vues:
34
Funny you should ask.. I was asking the same thing an hour ago in the thread above this one., As Kevin has told you, escaping each singlel quote with another single quote will do it, but be sure to check out Boris's example and the thread itself as the code is very cool.

Message ID: 1582747

>Hi All -
>
>My query is built with an SQL string that is executed by separate command.
>declare @SQL nvarchar(max), @Columns VARCHAR(max)
>
>set @columns = stuff((
>select ', ' + quotename(FundType) 
>FROM ( 
>SELECT FundType 
>FROM LookupFundtypes P ) S
>WHERE FundType <> ''
>ORDER BY FundType 
>FOR XML PATH('')), 1,2,'') 
>
>print @Columns
>
>set @SQL = 
>';with cte as (
>SELECT * 
>FROM (
>SELECT sponsor, fundtype, amount
>from TIP_ApprovedFunding f
>inner join TIP_Projects p on p.TipID = f.TipID
>where p.ApprovedStatus = [Active] 
> )
> select * from cte  
> PIVOT
> (
>   Sum(amount)
>   FOR [FundType]
>   IN (' + @Columns + ')
> ) AS PivotTableAlias'
> 
>execute sp_ExecuteSQL @SQL
>Note that it attempts to embed a string 'Active' inside the main sql string. This is erroring out with a message of 'incorrect syntax near SELECT'. I am fairly sure the problem is delineating the word 'Active'. Can someone tell me how to do this, or do you see something else wrong with the query?
>
>Thanks UT is great!


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform