如何使用SQL代码检查表的列中是否存在值?

时间:2022-10-16 07:54:44

I want to check if an employee number (EX:3424), which is read from a file, exists in a table or not using SQL.

我想检查从文件中读取的员工编号(EX:3424)是否存在于表中或不使用SQL。

If a record with the given employee number exists, then I have to perform a set of operations. Otherwise, I have to perform some other operations.

如果存在具有给定员工编号的记录,那么我必须执行一组操作。否则,我必须执行一些其他操作。

I am using DB2-cobol.

我正在使用DB2-cobol。

1 个解决方案

#1


1  

The SQL would be something like this to check for the existence of a given record:

SQL将是这样的,以检查给定记录的存在:

SELECT 1
FROM Employee_Table 
WHERE Employee_Number = 3424;

This will return one result or none. From there you will be able to tell if a record with the given employee number exists in the database table.

这将返回一个结果或没有结果。从那里,您将能够判断数据库表中是否存在具有给定员工编号的记录。

Here is a helpful link on SQL SELECT Statements.

这是SQL SELECT语句的有用链接。

As for the conditional logic, it would be something like this:

至于条件逻辑,它将是这样的:

IF EXISTS (SELECT 1 FROM Employee_Table WHERE Employee_Number = 3424)
     <Set of operations>
ELSE
     <Some other operations>

#1


1  

The SQL would be something like this to check for the existence of a given record:

SQL将是这样的,以检查给定记录的存在:

SELECT 1
FROM Employee_Table 
WHERE Employee_Number = 3424;

This will return one result or none. From there you will be able to tell if a record with the given employee number exists in the database table.

这将返回一个结果或没有结果。从那里,您将能够判断数据库表中是否存在具有给定员工编号的记录。

Here is a helpful link on SQL SELECT Statements.

这是SQL SELECT语句的有用链接。

As for the conditional logic, it would be something like this:

至于条件逻辑,它将是这样的:

IF EXISTS (SELECT 1 FROM Employee_Table WHERE Employee_Number = 3424)
     <Set of operations>
ELSE
     <Some other operations>