我有一个sql查询,我需要根据查询中生成的varchar中的倒数第三个数字删除特定行。该查询采用格式为" yyyy-MM-dd hh:mm:ss"的小日期时间。并将其变成varchar。例如:日期" 2015-05-04 06:03:00"将成为varchar 05040603.我需要删除任何行项目,其中第三个到最后一个varchar数字是9,1,4或0.这是我当前的代码:
SELECT DISTINCT
RIGHT('0' + CAST(DATEPART(M, TableA.DateTime) AS varchar), 2)
+ RIGHT ('0' + Cast(DATEPART(DD, TableA.DateTime) AS varchar), 2)
+ RIGHT('0' + CAST(DATEPART(HH, TableA.DateTime) AS varchar), 2)
+ RIGHT('0' + CAST(DATEPART(MINUTE, TableA.DateTime) AS varchar), 2) AS 'VarChar Number',
ColA, DateTime
FROM
TableA
WHERE
ColB IS NOT NULL
AND DateTime NOT IN (SELECT DateTime From TableB)
AND DateTime NOT IN (SELECT DateTime From tableC
WHERE DateTime IS NOT NULL)
在此示例中,表A具有较小的日期时间,并且正在从中生成varchar
个数字。 ColA来自表A,只是信息。 Where语句只是将日期时间与其他表进行交叉比较,以根据日期是否已显示在这些表中来删除它。
答案 0 :(得分:2)
您可以使用p(h.select do |k, v|
true
end)
执行此操作。
substring
答案 1 :(得分:1)
<body>
<div class="row">
<div class="small-12 medium-3 columns">
<ul class="dropdown menu" data-dropdown-menu="" role="menubar" data-dropdownmenu="3z4e20-dropdownmenu" aria-selected="false" aria-expanded="false" data-is-click="false">
<li role="menuitem" class="has-submenu is-dropdown-submenu-parent is-down-arrow" aria-haspopup="true" aria-selected="false" aria-expanded="false" aria-label="Actions" data-is-click="false">
<a href="#" tabindex="0">Actions</a>
<ul class="menu submenu is-dropdown-submenu first-sub vertical" data-submenu="" aria-hidden="true" role="menu">
<li role="menuitem" class="is-submenu-item is-dropdown-submenu-item"><a data-open="change-password-modal-0" aria-controls="change-password-modal-0" id="8p079l-reveal" aria-haspopup="true" tabindex="0">Change Password</a>
</li>
<li role="menuitem" class="is-submenu-item is-dropdown-submenu-item"><a href="#">Disable</a></li>
<li role="menuitem" class="is-submenu-item is-dropdown-submenu-item"><a href="#">Delete</a></li>
<li role="menuitem" class="is-submenu-item is-dropdown-submenu-item"><a href="#">Transfer</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="reveal" id="change-password-modal-0" data-reveal="rcsjob-reveal" data-reset-on-close="true" aria-labelledby="8p079l-reveal" role="dialog" aria-hidden="true" data-yeti-box="change-password-modal-0" data-resize="change-password-modal-0">
<h1>Change Password</h1>
<p class="lead">You are changing the password for:</p>
<label>Password: <input type="text"></label>
<button class="close-button" data-close="" aria-label="Close reveal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
</body>
答案 2 :(得分:0)
...
WHERE
ColB IS NOT NULL
AND DateTime NOT IN (SELECT DateTime From TableB)
AND DateTime NOT IN (SELECT DateTime From tableC
WHERE DateTime IS NOT NULL)
and datepart(minute, TableA.DateTime) % 10 not in (0, 1, 4, 9)
我不认为有任何理由搞乱字符串值,只需提取分钟并使用它。更清楚地理解意图并避免像vkp的回答那样的问题,并且意外地看到第6个位置而不是第8个位置。