我有一个问题。我想在sql中写这个条件:
AnyString.StartsWith(String1 + "_" + String2) or AnyString.StartsWith(String2 + "_" + String1)
例如,我想创建一个函数:
string commandString = "UPDATE [AnyTable] Set [AnyColumn]='Something' WHERE and here the condition above";
答案 0 :(得分:5)
选择:
Select *
From Table1
Where Field1 Like string1 + '[_]' + string2 + '%'
Or Field1 Like string2 + '[_]' + string1 + '%'
更新:
Update Table1
Set Field2 = 'YourValue'
Where Field1 Like string1 + '[_]' + string2 + '%'
Or Field1 Like string2 + '[_]' + string1 + '%'
答案 1 :(得分:4)
Update Table_A
set Column_B = 'WhatEver'
where column_C like String1 + '[_]' + String2 +'%'
or column_C like String2 + '[_]' + String1 +'%'
答案 2 :(得分:1)
select * from Foo where Bar LIKE 'string%'
(其中%是通配符意味着匹配任何内容)
答案 3 :(得分:1)
试试这个:
"UPDATE [AnyTable] Set [AnyColumn]='Something' WHERE first_col LIKE
sometext_othertext% OR second_col LIKE sometext_othertext%"
使用%,您可以选择以下一个单词开头的文本句子。
http://technet.microsoft.com/en-us/library/ms179859.aspx(SQL LIKE)
答案 4 :(得分:0)
string commandString = "UPDATE [AnyTable]
Set [AnyColumn]='Something'
WHERE AnyString like String1 + "_" + String2 + "%" or AnyString like String2 + "_" + String1 + "%";