Pivot table not showing the Data in sqlserver
===

I am new to sqlserver, i am facing the problem to display the data using pivot tables. 
my table structure is as:
   

     UserName    VisitedDate    Amount   Visted
        bbb	    2012-07-05	    200	      1
        bbb	    2012-06-03	    300	      3
        ccc	    2012-04-15	    500	      5
        ccc	    2012-06-30	    600	      3

i searched a lot and found something useful  as:

    DECLARE @Sql VARCHAR(8000)
    DECLARE @ColumnNames VARCHAR(1000)
    DECLARE @BeginDate DATETIME
    DECLARE @EndDate DATETIME
    declare @AAmount varchar(1000)

    SET @BeginDate = '2012-4-1'
    SET @EndDate = '2013-3-30'
    SET @ColumnNames = ''
    set @AAmount = ''

    WHILE @BeginDate <= @EndDate
    BEGIN
     SET @ColumnNames = @ColumnNames + ',[' + DateName(month,@BeginDate) + '_' +     Cast(Year(@BeginDate) AS VARCHAR(4)) + ']'
    SET @AAmount = @AAmount + ',[' +'Amount'+ DateName(month,@BeginDate) + '_' +   Cast(Year(@BeginDate) AS VARCHAR(4)) + ']'
    SET @BeginDate = DateAdd(Month, 1, @BeginDate)
    END
    IF Len(@ColumnNames) > 0
    SET @ColumnNames = Right(@ColumnNames, Len(@ColumnNames) - 1)

    PRINT @ColumnNames
    IF Len(@AAmount) > 0
    SET @AAmount = Right(@AAmount, Len(@AAmount) - 1)

    PRINT @AAmount

 
    SET @Sql = '
    WITH U AS
    (
      SELECT UserName, DateName(month,Visited_Date) + ''_'' + Cast(Year(Visited_Date) AS VARCHAR(4)) AS VisitedMonth,Amount,DateName(month,Visited_Date) + ''_'' + Cast(Year(Visited_Date) AS VARCHAR(4)) AS VisitedMonth1,Visited
        FROM Users 
    )
    SELECT  *
    FROM U 
 
    PIVOT (
    SUM(Amount) FOR VisitedMonth IN (' + @ColumnNames + ')
    ) AS P1
    PIVOT (
    SUM(Visited) FOR VisitedMonth1 IN (' + @AAmount + ')
    ) AS  pivotable'


     EXEC (@Sql)

and the Result set is as Follows:

    UserName AprilAmount_2012  MayAmt_2012 JuneAmt_2012 April_2012  May_2012    June_2012
    bbb	     NULL	           NULL         NULL	    NULL	       NULL	     NULL
    bbb	     NULL	           NULL         300	        NULL	       NULL	     NULL
    ccc	     NULL	           NULL         600	        NULL	       NULL	     NULL
    ccc	     500	           NULL         NULL	    NULL	       NULL	     NULL

**Please Note that amt. in header is Amount**

Now my Problem is that 
**1)** For 3 columns in the table it shows the data but i tried to add one more column visited then it is not displaying the expected result....

**2)** I also want to rearrange the Columns as :

    UserName AprilAmount_2012 April_2012 MayAmt_2012  May_2012   JuneAmt_2012   June_2012
    bbb	     NULL	           NULL           NULL	     NULL	       NULL	        NULL
    bbb	     NULL	           NULL           NULL	     NULL	       300	        3
    ccc	     NULL	           4              NULL	     NULL	       600	        NULL
    ccc	     500	           NULL           NULL	     NULL	       NULL	        5

**3)** also I want the Unique names to be displayed...
Please Help me or Tell me the Way so that i can able to find the Solution.
 Any kind of help is appreciated.

Thanks in Advance ...

Ranjan
