SQL Statemet [英] SQL Statemet

查看:234
本文介绍了SQL Statemet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这里我做错了什么吗?我正在尝试使用此方法返回seqnbr。

展开 | 选择 | Wrap | <跨度类= codeLink 的onclick = LineNumbers(本);>行号

解决方案
为什么你相信你做错了什么?你没有提到错误信息,也没有提到你所得到的*不是你所期望的。


但粗略猜测...

第4行你为SeqNbr指定零

第19行你返回SeqNbr

所以你可能得到零返回,对吗?


它没有返回序列号。基本上,它应该遍历员工记录并找到第一个可用的序列号,然后将其返回到调用代码。这将允许我使用可用数字输入新记录,而不是在序列中有间隙。


所以让我们一起弄清楚。除非在这里比我在SQL中更有经验的人想要加入。


它应该通过所有员工。

我假设第7-12行设置了SQL语句来创建通过雇员的循环。它看起来像是一个C#''While'循环。


我认为你将@seq设置为1,检查是否有一个有这个号码的员工,然后递增@seq并再次检查。如果没有这个号码的员工,那么它应该落到第13行。


所以我的问题是这个......你在什么时候分配了@的值seq回到SeqNbr?我看到的最接近的是第13行,其中END为SeqNbr。 'end''以某种方式保留了@seq的价值吗?因为如果它没有,除了我之前提到的地方,我不会看到SeqNbr 曾经使用的地方。


Line 4你给零指定零点

第19行你返回SeqNbr

所以你可能得到归零,对吧?



SeqNbr现在返回什么价值?


作为测试,如果你指定SeqNbr你会认识到一些奇怪的价值,比如


4. int SeqNbr = 1313;


你在结束时得到1313运行,然后您知道您的查询不会以任何方式影响SeqNbr。如果你的查询正在影响SeqNbr,那么你初始化它并不重要,因为无论如何你都要改变它。


Can someone tell me what I''m doing wrong here? I''m trying to get this method to return the seqnbr.

Expand|Select|Wrap|Line Numbers

解决方案

Why do you beleive you are are doing something wrong? You made no mention of an error message or what you *are* getting that isn''t what you expected.

But as a rough guess...
Line 4 you assign zero to SeqNbr
Line 19 you return SeqNbr
So you are probably getting zero returned, right?


It''s not returning the sequence number. Basically, it is supposed to step through the employees records and find the first available sequence number then return it to the calling code. This would allow me to enter new records using available numbers rather than having gaps in the sequence.


So let''s figure it out together. Unless someone here more experienced than I in SQL would like to jump in.

Its is supposed to step through all the employees.
I''m assuming lines 7-12 set up the SQL statement to create the loop going through the employes. It reads like it might behave like a C# ''While'' loop.

I think you are setting @seq to 1, checking to see if there is an employee with that number, then incrementing @seq and checking again. If there is no employee with that number, then it should fall through to line 13.

So my question to you is this... at what point do you assign the value of @seq back to SeqNbr? The closest I see is line 13 with END as SeqNbr. Does ''end'' somehow hold the value of @seq? Because if it doesn''t, I don''t see where SeqNbr is ever used except where I earlier mentioned.

Line 4 you assign zero to SeqNbr
Line 19 you return SeqNbr
So you are probably getting zero returned, right?

What value do you get returned right now by SeqNbr?


As a test, if you assign SeqNbr some weird value that you will recognize like

4. int SeqNbr = 1313;

and you get 1313 returned at the end of your run, then you know your query is not affecting SeqNbr in any way. If your query is affecting SeqNbr, then it won''t matter what you initialize it to since you are going to change it anyway.


这篇关于SQL Statemet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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