如何识别表中的行/重新记录的结尾 [英] How to identify end of rows/recodrs in a table

查看:76
本文介绍了如何识别表中的行/重新记录的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如果有人能协助我解决问题,我们会有所帮助。我有一张下表,我想知道表格中是否有更多行。



表名:测试



姓名姓氏

----- -------

Gena |结婚

Sam |斯科特

四月| Jones



实际问题是,当且仅当列中没有重复'LastName'时,我想插入一条新记录。 (即如果LastName是Scott,则不应该插入新记录和/或LastName是Rio,那么只应插入新记录。



请协助。

解决方案

以下是您要实现的目标的步骤



1.写一个小的存储过程传递要插入表中的所有值。

2.检查与您传递的姓氏匹配的姓氏数。

3.如果count为0,则插入记录



如果你不明白我想说的话然后检查下面的代码

 < span class =code-keyword> create   procedure  CheckCountOfLastName( @ name   varchar  20 ), @ lastname   varchar  20 ))
as
声明 @ count 数字
选择 @ count = count(姓氏)来自 yourtablename 其中​​ lastname = @ lastname
if @ count = 0
开始
插入 into yourtablename(name,lastname) values @ name @ lastname
end



希望有所帮助


Hi All,

It will we helpful if some could assist me resolving the issue. I've a following table and I want to know if there are no more rows in the table.

Table Name: Test

Name LastName
----- -------
Gena | Marry
Sam | Scott
April | Jones

The actual problem is, I want to insert a new record if and only if 'LastName' is not repeated in the column. (i.e. If LastName is Scott then there should be no new record inserted and /or LastName is Rio then only new record should be inserted.

Please assist.

解决方案

The follow are the steps for what you want to achieve

1. Write a small stored procedure where you pass all the values to be inserted in the table.
2. Check count of lastname which matches with the lastname you have passed.
3. if count is 0 the insert the record

if you dont understand what I am trying to say then check the code below

create procedure CheckCountOfLastName(@name varchar(20), @lastname varchar(20))
as
	declare @count numeric
	select @count = count(lastname) from yourtablename where lastname=@lastname
	if (@count = 0)
	begin
		insert into yourtablename(name, lastname) values(@name, @lastname)
	end


Hope it helps


这篇关于如何识别表中的行/重新记录的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆