Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-06-11 : 23:59:39
|
| With this procedure,can't show if GiftTitle contains space ,nonalphabetic chars(&,-,..) and if start with numnber.How can i modify ??Plz help me.Thanks.CREATE PROCEDURE dbo.trymatrix ASDECLARE @SQLCommand varchar(4096), @column sysnameSET @SQLCommand = 'select c.CustomerID as Cust_ID,Name as Co_Name, ' + char(13)DECLARE curGift CURSOR STATIC LOCAL FORselect distinct GiftTitle from Redemption1OPEN curGiftWHILE 1 = 1BEGINFETCH curGift INTO @columnIF @@FETCH_STATUS <> 0BREAKSET @SQLCommand = @SQLCommand +'sum(case GiftTitle when ''' +@column +''' then 1 else null end) as '+ @column + ','+char(13)ENDDEALLOCATE curGift SET @SQLCommand = left (@SQLcommand, len(@SQLcommand)-2) + char(13)SET @SQLCommand = @SQLCommand + 'from Customer c inner join Redemption1 don c.CustomerID=d.CustomerIDgroup by Name,c.CustomerIDorder by c.CustomerID'PRINT @SQLCommandEXEC (@SQLCommand) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-12 : 00:48:36
|
WHERE SomeCol NOT LIKE '%[^a-z]%' E 12°55'05.25"N 56°04'39.16" |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-06-12 : 01:25:11
|
Thanks.Now i changed to like:SET @SQLCommand = @SQLCommand +'sum(case GiftTitle when ''' +@column +''' then 1 else null end) as ['+ replace(replace(@column, '[', '_'), ']', '_') + '],'+char(13)quote: Originally posted by Peso WHERE SomeCol NOT LIKE '%[^a-z]%' E 12°55'05.25"N 56°04'39.16"
|
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-12 : 02:22:42
|
Or more simplersum(case GiftTitle when ' + quotename(@column, '''') + ' then 1 else null end) as ' + quotename(@column) + ',' + char(13)This is also take care of single quote character " ' " and ending bracket " ] ". E 12°55'05.25"N 56°04'39.16" |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-06-12 : 04:24:54
|
Great!Now i changed mine with yours.Thanks Peso.quote: Originally posted by Peso Or more simplersum(case GiftTitle when ' + quotename(@column, '''') + ' then 1 else null end) as ' + quotename(@column) + ',' + char(13)This is also take care of single quote character " ' " and ending bracket " ] ". E 12°55'05.25"N 56°04'39.16"
|
 |
|
|
|
|
|
|
|