选择包含正方形2的字符串

时间:2018-12-20 10:46:25

标签: sql-server

我要选择包含正方形2(此字符'²')的行

我做了select myColumn from table where myColumn '%²%'
我得到了包含“²”的列以及包含“ 2”的列。

我尝试了select myColumn from table where myColumn '%2%'并且得到了相同的结果。

SQL Server中是否有一种方法可以选择仅包含2个平方字符的列?

2 个答案:

答案 0 :(得分:3)

您必须使用适当的排序规则,例如$source = Join-Path -Path $ENV:UserProfile -ChildPath "Documents\Test\DataSD.xls" $maxArraySize = 2000 $Excel = New-Object -ComObject Excel.Application # It would speed up things considerably if you set $Excel.Visible = $false $WorkBook = $Excel.Workbooks.Open($source) $WorkSheet = $WorkBook.WorkSheets.Item(1) $WorkSheet.Activate() # Create a Hashtable object to store each array under its own key # I don't know if you need to keep the order of things later, # but it maybe best to use an '[ordered]' hash here. # If you are using PowerShell version below 3.0. you need to create it using # $hash = New-Object System.Collections.Specialized.OrderedDictionary $hash = [ordered]@{} # Create an ArrayList for better performance $list = New-Object System.Collections.ArrayList # Initiate a counter to use as Key in the Hashtable $arrayCount = 0 # and maybe a counter for the total number of items to process? $totalCount = 0 # Start reading the Excel data. Begin at row $row $row = 2 do { $list.Clear() # Add the values of column 1 to the arraylist, but keep track of the maximum size while ($WorkSheet.Cells.Item($row, 1).Value() -ne $null -and $list.Count -lt $maxArraySize) { [void]$list.Add($WorkSheet.Cells.Item($row, 1).Value()) $row++ } if ($list.Count) { # Store this array in the Hashtable using the $arrayCount as Key. $hash.Add($arrayCount.ToString(), $list.ToArray()) # Increment the $arrayCount variable for the next iteration $arrayCount++ # Update the total items counter $totalCount += $list.Count } } while ($list.Count) # You're done reading Excel data, so close it and release Com objects from memory $Excel.Close() [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WorkSheet) | Out-Null [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WorkBook) | Out-Null [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) | Out-Null [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() # At this point you should have all arrays stored in the hash to process Write-Host "Processing $($hash.Count) arrays with a total of $totalCount items" foreach ($key in $hash.Keys) { # Send each array to a SAP business objects query separately # The array itself is at $hash.$key or use $hash[$key] }

Latin1_General_BIN

答案 1 :(得分:1)

在不区分大小写的排序规则中,SQL Server似乎将ActiveSheet'2'视为相同字符(在SQL Server看来'²'是小写的'²')吗? )。例如,如果运行以下命令:

'2'

输出为:

SELECT CASE N'²' COLLATE Latin1_General_CS_AS WHEN N'2' COLLATE Latin1_General_CS_AS THEN 1 ELSE 0 END AS Sensitive,
       CASE N'²' COLLATE Latin1_General_CS_AI WHEN N'2' COLLATE Latin1_General_CS_AI THEN 1 ELSE 0 END AS CaseSensitive,
       CASE N'²' COLLATE Latin1_General_CI_AS WHEN N'2' COLLATE Latin1_General_CI_AS THEN 1 ELSE 0 END AS AccentSensitive,
       CASE N'²' COLLATE Latin1_General_CI_AI WHEN N'2' COLLATE Latin1_General_CI_AI THEN 1 ELSE 0 END AS Insensitive;

如果您希望Sensitive CaseSensitive AccentSensitive Insensitive ------------ ------------- --------------- ----------- 0 0 1 1 '2'被区别对待,则需要使用区分大小写的排序规则。