Error: Unclosed quotation mark after WHILE (@7DaysEarlierPartitionIntegerId &lt;= @CurrentPartitionIntegerId)
    BEGIN
        Set @7DaysEarlierPartitionId 
            = CAST(@7DaysEarlierPartitionIntegerId AS char)
        set @sqlCommand 
            = 'Select * from ' 
              + quotename(@RequestUsage_Partition + @7DaysEarlierPartitionId)
              + 'where UserLogin like''r2\rohit.kharade'
        exec(@sqlCommand)
        set @7DaysEarlierPartitionIntegerId 
            = @7DaysEarlierPartitionIntegerId + 1
    END


I get the error:


  Unclosed quotation mark after the character string 'r2\rohit.kh'.


How to execute the exec command with UserLogin =%r2\rohit.kharade%
You're missing the end quote, this should get you there.

WHILE (@7DaysEarlierPartitionIntegerId &lt;= @CurrentPartitionIntegerId)
    BEGIN
        Set @7DaysEarlierPartitionId 
            = CAST(@7DaysEarlierPartitionIntegerId AS char)
        set @sqlCommand 
            = 'Select * from ' 
              + quotename(@RequestUsage_Partition + @7DaysEarlierPartitionId)
              + 'where UserLogin like ''r2\rohit.kharade'''
        exec(@sqlCommand)
        set @7DaysEarlierPartitionIntegerId 
            = @7DaysEarlierPartitionIntegerId + 1
    END


I generally like to use CHAR(39) in place of multiple quotes, just to make code more readable 

WHILE (@7DaysEarlierPartitionIntegerId &lt;= @CurrentPartitionIntegerId)
    BEGIN
        Set @7DaysEarlierPartitionId 
            = CAST(@7DaysEarlierPartitionIntegerId AS char)
        set @sqlCommand 
            = 'Select * from ' 
              + quotename(@RequestUsage_Partition + @7DaysEarlierPartitionId)
              + 'where UserLogin like ' + CHAR(39) + 'r2\rohit.kharade' + CHAR(39)
        exec(@sqlCommand)
        set @7DaysEarlierPartitionIntegerId 
            = @7DaysEarlierPartitionIntegerId + 1
    END


Bonus thought, just as another, more readable version, you could also QUOTENAME

WHILE (@7DaysEarlierPartitionIntegerId &lt;= @CurrentPartitionIntegerId)
    BEGIN
        Set @7DaysEarlierPartitionId 
            = CAST(@7DaysEarlierPartitionIntegerId AS char)
        set @sqlCommand 
            = 'Select * from ' 
              + quotename(@RequestUsage_Partition + @7DaysEarlierPartitionId)
              + ' where UserLogin like ' + QUOTENAME('r2\rohit.kharade', CHAR(39))
        exec(@sqlCommand)
        set @7DaysEarlierPartitionIntegerId 
            = @7DaysEarlierPartitionIntegerId + 1
    END