Home > Back-end >  In statement in the SQL server2000
In statement in the SQL server2000

Time:09-25

In statement in the SQL error if the string is query,
M2:='p001 p002,'
Select * from kucuntx where ypbh in (' + m2 + ') '

Server: Msg 207, Level 16, State 3, Line 3
Invalid column name 'p002'.
Server: Msg 207, Level 16, State 1, Line 3
Invalid column name 'p001'.
But if it is: m2:='111222' query sure

CodePudding user response:

M2:=' 'p001' ', ' 'p002' ' '

CodePudding user response:

I get m2 format is' p001, p002 to convert in statement to identify the format: 'p001', 'p002'

CodePudding user response:

If m2 is digital type, such as: '100200', In In statement is no problem, In (' + m2 + '), if it's character, using the In (' + m2 +) have a problem, the
'p100, p200' convert 'p100', 'p200 format In statement to identify

CodePudding user response:

Can be performed in the SQL Server for the following statement,
 with table1 as 
(
Union all select 1 id
Union all select 3 id
Union all select 5 id
Union all select 7 id
Union all select 9 id
Union all select 11 id
Union all select 13 id
Union all select 15 id
Union all select 17 id
Select the id
)
Select * from table1 where id in (' 1 ', '2', '3')


Test shows that the string can be automatically converted into digital,
Therefore, no matter what kind of m2 get content, are converted into text, examples are as follows:
If the m2:='p001, p002, is converted to m2:=' ' 'p001' ', ' 'p002' ' '
If m2:='100200', it is converted into m2:=' ' '100', '200' ' '
Like this, both characters or digital, in (' + m2 +) there will be no mistake,

CodePudding user response:

Delphi SQL string in double quotes

CodePudding user response:

Better advice so write, read:
'select * from kucuntx where ypbh (in' 39 + m2 + + # # 39 + ') '
Or parameters is good too

CodePudding user response:

SQL is a collection of IN
For integer: in (6)
For character: in (' 1 ', '2', '3', '4', '5', '6')

M2:='p001 p002,//the expression should be: m2:=' p001 ', 'p002'

Select * from kucuntx where ypbh '(' + m2 +') 'in//there is no problem

CodePudding user response:

I don't understand is to add a string of single quotes, is that Numbers can success only SQL directly, better for their strict requirements.
  • Related