priya ppp

priya ppp

  • NA
  • 16
  • 8.2k

Query to get the count

Jan 12 2016 11:54 PM
Hi  to every one ..I want to get a count from variable ,please check the below query
 
'DECLARE @PATOIDS VARCHAR(MAX) ' +
'DECLARE @Pat VARCHAR(MAX) '+
'SET @PATOIDS = '''' ' +
'SELECT @PATOIDS = @PATOIDS + CAST(PATIENTOID AS VARCHAR) + '','' ' +
'FROM (SELECT DISTINCT PATIENTOID ' +
'FROM @CNT) TMP ' +
'IF LEN(@PATOIDS) > 0 ' +
'SET @PATOIDS = SUBSTRING(@PATOIDS, 1, LEN(@PATOIDS) - 1)'
 
 In the above query '@PATOIDS' contains multiple values , to print the values in @PATOIDS,am using the statement like
 
'DECLARE @PATOIDS VARCHAR(MAX) ' +
'DECLARE @Pat VARCHAR(MAX) '+
'SET @PATOIDS = '''' ' +
'SELECT @PATOIDS = @PATOIDS + CAST(PATIENTOID AS VARCHAR) + '','' ' +
'FROM (SELECT DISTINCT PATIENTOID ' +
'FROM @CNT) TMP ' +
'IF LEN(@PATOIDS) > 0 ' +
'SET @PATOIDS = SUBSTRING(@PATOIDS, 1, LEN(@PATOIDS) - 1)'+
+'PRINT(@PATOIDS)'
 
but the out put contains the values along with comma separated values but I want to print the count of  @PATOIDS, so can any one tell me how to get the count??
 

Answers (1)