Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Sql server strings are equal! ! ! The type of my hometown is nchar( 10), why are they all from other provinces and cities! ! !
Sql server strings are equal! ! ! The type of my hometown is nchar( 10), why are they all from other provinces and cities! ! !
Use CHARINDEX () to judge.

Select a name, (

When CHARINDEX ('Henan', native place) > 0, it is' from Henan'.

When CHARINDEX ('Jiangxi', native place) > 0, it is' from Jiangxi'

When CHARINDEX ('Shaanxi', native place) > 0, it is' from Shaanxi'

When CHARINDEX ('Anhui', native place) > 0, it is' from Anhui'

When CHARINDEX ('Fujian', native place) > 0, it is' from Fujian'

Else' from other provinces and cities'

End) is a native place.

Information from teachers

You can also use it as your native place =' Fujian' and then' from Fujian'

Both should have the same output.

CHARINDEX ('Fujian', native place) > 0 indicates that the native place field contains' Fujian'.