Note that there are some explanatory texts on larger screens.

plurals
  1. POSql in sql server with convert
    primarykey
    data
    text
    <p>I am trying to use convert in an where clause in the select statement. My query looks like this:</p> <pre><code>SELECT DISTINCT TOP 10 [SurveyResult].* ,[Ticket].[RefNumber] FROM [SurveyResult] LEFT JOIN [Ticket] ON [SurveyResult].[TicketID] = [Ticket].[TicketID] JOIN [SurveyResponse] AS SurveyResponse1 ON [SurveyResult].[ResultID] = SurveyResponse1.[ResultID] JOIN [QuestionAnswer] AS QuestionAnswer1 ON SurveyResponse1.[AnswerID] = QuestionAnswer1.[AnswerID] JOIN [SurveyQuestion] AS SurveyQuestion1 ON QuestionAnswer1.[QuestionID] = SurveyQuestion1.[QuestionID] WHERE SurveyQuestion1.[SurveyID] = [SurveyResult].[SurveyID] AND SurveyQuestion1.[QuestionID] = 'C86CB39A-8FE0-4FE8-B38F-17F1BE611016' AND CONVERT(INT, SurveyResponse1.[Response]) &gt;= 1 AND CONVERT(INT, SurveyResponse1.[Response]) &lt;= 5 </code></pre> <p>The problem is that I get some errors when converting the values to integer in the where statement.</p> <p>I know I have some rows that don't contain numbers in the Response column but I filter those so without the convert part in the where clause I get only numbers so it works like this:</p> <pre><code>SELECT TOP 1000 [ResponseID] ,[ResultID] ,[Response] FROM [WFSupport].[dbo].[SurveyResponse] JOIN QuestionAnswer ON SurveyResponse.AnswerID = QuestionAnswer.AnswerID WHERE QuestionAnswer.QuestionID = 'C10BF42E-5D51-46BC-AD89-E57BA80EECFD' </code></pre> <p>And in the results I get numbers but once I add the convert part in the statement I I get an error that it can't convert some text to numbers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload