使用Sql Server 2012.我有一个存储过程,其中一部分检查用户名是否在表中.如果是,则返回1,如果不是,则返回2.这是我的代码:
IF EXISTS (SELECT * FROM tblGLUserAccess WHERE GLUserName ='xxxxxxxx') 1 else 2
Run Code Online (Sandbox Code Playgroud)
但是,我一直收到以下错误:
'1'附近的语法不正确.
这是否可以通过IF EXIST实现?
问候,
迈克尔
sql sql-server stored-procedures if-statement sql-server-2012
我有通过 SSIS 进程任务调用的以下 PowerShell 脚本来检查文件是否被锁定 - 如何修改以便它首先检查文件是否存在。
如果不存在,则以 999 退出
如果它确实存在但被锁定,则以 999 退出
如果它确实存在并且未被锁定,则以 0 退出
$file = "\\xxxxxx\xxxx\xxxxx\xxxxxxxxx\task_status.log"
try { [IO.File]::OpenWrite($file).close();exit 0 } catch { exit 999}
Run Code Online (Sandbox Code Playgroud)我正在通过 SQL Server 执行以下 DB2 SQL(因此需要在 DB2 SQL 中):
exec ('
select
TRIM (vhitno) AS "Item",
TRIM (mmitds) AS "Description",
TRIM (SUBSTRING (vhitno,12,4)) AS "Size",
vhalqt AS "Available"
from m3fdbtest.oagrln
left outer join m3fdbtest.mdeohe
on vhcono = uwcono
and vhcuno = uwcuno
and vhagno = uwagno
and vhitno = uwobv1
left outer join m3fdbtest.mitmas
ON vhcono = mmcono
AND vhitno = mmitno
where uwcono = 1
and uwstdt >= ?
and uwlvdt <= ?
and uwcuno = ''JBHE0001''
and uwagst …Run Code Online (Sandbox Code Playgroud) MS SQL Server 2014。
我有一个运行良好的 SQL 语句:
SELECT CONCAT (
CAST(T1.[F1] AS INTEGER),
CAST(T1.[F2] AS INTEGER)
) AS F3
FROM mytable AS T1
Run Code Online (Sandbox Code Playgroud)
如果我然后将其放入视图中,并尝试运行,我会收到错误:
Operand data type int is invalid for concat operator
Run Code Online (Sandbox Code Playgroud)
F1 和 F2 都包含小数,但我希望它们连接,例如:
F1 = 123.00000
F2 = 456.00000
Run Code Online (Sandbox Code Playgroud)
所以F3 = 123456
为什么视图不允许这样做,有解决方案吗?
由于某种原因(我无法控制),日期将作为整数存储在我需要查询的iSeries AS400 DB2系统中.例如今天将存储为:
20,171,221
Run Code Online (Sandbox Code Playgroud)
在英国,我需要它在日期格式中如下所示:
21/12/2017
Run Code Online (Sandbox Code Playgroud)
这是我的查询:(OAORDT =日期字段)
Select
Date(SUBSTR( CHAR( OAORDT ),7,2) ||'/' || SUBSTR(CHAR ( OAORDT ),5,2) || '/' || SUBSTR(CHAR (OAORDT ),1,4)) AS "Order Date"
from some.table
Run Code Online (Sandbox Code Playgroud)
但是,我得到的只是Nulls.如果我删除Date函数,那么它确实有效但它现在是一个我不想要的字符串:
Select
SUBSTR( CHAR( OAORDT ),7,2) ||'/' || SUBSTR(CHAR ( OAORDT ),5,2) || '/' || SUBSTR(CHAR (OAORDT ),1,4) AS "Order Date"
from some.table
Run Code Online (Sandbox Code Playgroud)
如何将OAORDT字段转换为日期?
只是为了更新 - 我将使用OpenQuery从MS SQL Server查询它
谢谢.
我正在使用MS SQL Server。
我有下表:
SKU Shop WeekNum ShopPrioirty Replen OpeningStock
111 100 1 1 10 5000
111 200 1 2 10 NULL
111 300 1 3 5 NULL
111 400 1 4 8 NULL
222 100 2 1 20 6000
222 200 2 2 15 NULL
222 300 2 3 12 NULL
222 400 2 4 10 NULL
Run Code Online (Sandbox Code Playgroud)
这是期望的结果:
SKU Shop WeekNum ShopPrioirty Replen OpeningStock
111 100 1 1 10 5000
111 200 1 2 10 4990
111 300 1 …Run Code Online (Sandbox Code Playgroud) 我在 MS SQL Server 中有下表:
RowID PersonNum Address1
1 456 1 My street
2 NULL 1 My street
3 789 1 My street
4 987 2 My street
5 963 2 My street
6 852 3 My street
7 741 3 My street
8 NULL 3 My street
Run Code Online (Sandbox Code Playgroud)
我想删除同一地址中的所有行,其中至少有一个 personnum = NULL
所以从上面,我需要删除 RowID 的 1、2、3、6、7、8。
RowID 的 4 和 5 没问题,因为它们有一个 PersonNum。我如何在 T SQL 中实现这一点?这可以使用 CTE 吗?
我正在使用SQL Server 2012.我需要删除比去年更大的数据.
到目前为止,例如,删除任何记录超过28/11 /更大的2015年.
虽然它正在滚动,但它将成为每天运行的SP的一部分,因此每天都会检查当前日期并删除.做这个的最好方式是什么?
DELETE tblmytable
where MyDateField > GETDATE ()
Run Code Online (Sandbox Code Playgroud)
我如何改变说>去年的今天?
我在SSIS中使用脚本任务(C#)将所有.txt文件从一个文件夹移动到另一个文件夹.但是,当我执行此操作时,没有任何反应.脚本任务实际上报告成功但文本文件不移动.我正在为所有路径使用变量 - 它们都以2个反斜杠开头,以1个反斜杠结束.
我想要做的就是将所有文本文件从源目标移动到目标文件夹.
我错过了什么?
public void Main()
{
DirectoryInfo di = new DirectoryInfo(Dts.Variables["IN_Folder"].Value.ToString());
string destinationFolder = Dts.Variables["User::IN_Folder_Processing"].Value.ToString();
string sourceFolder = Dts.Variables["User::IN_Folder"].Value.ToString();
FileInfo[] fi = di.GetFiles("*.txt");
String filename = fi[0].Name;
string sourceFileName = filename;
string destinationFile = destinationFolder + sourceFileName;
string sourceFile =sourceFolder + sourceFileName;
if (File.Exists(destinationFile))
File.Delete(destinationFile);
// To move a file or folder to a new location:
System.IO.File.Move(sourceFile, destinationFile);
Dts.TaskResult = (int)ScriptResults.Success;
}
Run Code Online (Sandbox Code Playgroud) 我有一张桌子:
RowID QuestionNum Survey
--------------------------------
ABC 1 1
DEF 2 1
ASD 3 1
RDS 4 1
TGH 5 1
YHG 1 2
TGF 2 2
UHJ 3 2
UJH 4 2
IJK 5 2
UJH 6 2
Run Code Online (Sandbox Code Playgroud)
RowID是字符串,QuestionNum和Survey是INT。
我要做的就是排除:
这是我的SQL:
SELECT RowID, QuestionNum, SurveyType
FROM dbo.tblTest
WHERE (SurveyType <> 1)
AND (QuestionNum <> 5)
OR (SurveyType <> 2) AND (QuestionNum <> 6)
Run Code Online (Sandbox Code Playgroud)
但是它返回所有行-我缺少什么?
谢谢。
sql ×7
sql-server ×7
t-sql ×4
db2 ×2
ibm-midrange ×2
c# ×1
casting ×1
date ×1
if-statement ×1
powershell ×1
sql-delete ×1
ssis ×1
view ×1
where-clause ×1