我的情况是字符串中的第6个和第7个字符需要等于' 73'。我尝试使用LIKE '%73%'
,但问题是有时SQL Server会遇到可能在字符串中的其他73。有没有办法只搜索字符串中的第6和第7个字符?
非常感谢你的帮助!
答案 0 :(得分:6)
使用SUBSTRING(表达式,开始,长度)
SELECT mycolumn
FROM mytable
WHERE SUBSTRING ( mycolumn ,6 , 2 ) = '73'
答案 1 :(得分:5)
使用like
,您可以:
where col like '_____73%'
当然,提出substring()
的其他解决方案也非常明智。
答案 2 :(得分:3)
使用SUBSTRING
:
SELECT SUBSTRING(YourColumn,6,2) Result
FROM dbo.YourTable;
您可以将其用作过滤器:
SELECT *
FROM dbo.YourTable
WHERE SUBSTRING(YourColumn,6,2) = '73';
答案 3 :(得分:2)
尝试使用SQL Server
m_sleepSearch = new QSignalTransition(this, &Base::next, m_sleep);
m_searchDestroy = new QSignalTransition(this, &Base::next, m_search);
m_searchReturn = new QSignalTransition(this, &Base::back, m_search);
m_destroySearch = new QSignalTransition(this, &Base::next, m_destroy);
m_destroyReturn = new QSignalTransition(this, &Base::back, m_destroy);
m_returnSearch = new QSignalTransition(this, &Base::next, m_return);
m_returnSleep = new QSignalTransition(this, &Base::back, m_return);
m_sleepSearch->setTargetState(m_search);
m_searchDestroy->setTargetState(m_destroy);
m_searchReturn->setTargetState(m_return);
m_destroySearch->setTargetState(m_search);
m_destroyReturn->setTargetState(m_return);
m_returnSearch->setTargetState(m_search);
m_returnSleep->setTargetState(m_sleep);
这可以找到字符串'73'从位置6开始的位置