I'm running an R language script under T-SQL where I use REGEX to validate data in two columns. However I only want to output the id column in my result set. My script is:
EXECUTE sp_execute_external_script
@language = N'R',
@script = N'
pattern = "^(?:[\\p{L}\\p{M}\\,\\-\\_\\.\\''…`\\s\\d]){1,255}+$"
firstnameOK <- subset(inData, grepl(pattern, FirstName, perl = TRUE))
lastnameOK <- subset(firstnameOK, grepl(pattern, LastName, perl = TRUE))
id <- levels(lastnameOK$id)
x <- data.frame(id)
outData <- x
',
@input_data_1 = N'SELECT [id], [FirstName], [LastName] FROM [dummy]',
@input_data_1_name = N'inData',
@output_data_1_name = N'outData'
WITH RESULT SETS ((id int))
However this fails with the error:
EXECUTE statement failed because its WITH RESULT SETS clause specified 1 result set(s), but the statement only sent 0 result set(s) at run time.
The data.frame() code came from a web search so there may be a better way to pull only the "id" column from the input.
Any ideas? Thanks.