我不能使用“DECLARE”吗? 在表函数中?
感谢您的消息,我像这样解决了我的问题,
ALTER FUNCTION [VEZNE].[fnMakbuzIslemGetir]
(
@refNo as int
)
RETURNS @tablename TABLE (kontrol1 char(1),key0 numeric(18,0) ,tarih datetime ,hizkod char(12),hizad char(75),ytlhizfiyat decimal(18,2) ,hizmiktar numeric(18,2),ytlhiztutar decimal(18,2))
AS
BEGIN
DECLARE @durum AS VARCHAR
DECLARE @hastaTuru AS VARCHAR
DECLARE @makTipi AS VARCHAR
SET @durum = (SELECT durum FROM TH_RefKart WHERE RefNo = @refNo)
SET @hastaturu = (SELECT HastaTuru FROM TH_Dosya WHERE DosyaNo in (SELECT DosyaNo FROM TH_RefKart WHERE RefNo = @refNo))
SET @makTipi = (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo )
IF ((@hastaTuru = 'Ücretli') AND (@durum = 'AYAKTA')) OR @makTipi = '0'
BEGIN
INSERT @tablename SELECT kontrol1, key0, tarih, hizkod, hizad, ytlhizfiyat, hizmiktar, ytlhiztutar
FROM TH_Islem
WHERE refno= @refNo and DekontNo = '0' and anahtar<> -1
END
RETURN
END
但现在我在这一行遇到了另一个问题,
SET @makTipi = (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo)
因为此 SELECT 返回多行值。 我现在能做什么?
Thanks for your message I solved my problem like this
ALTER FUNCTION [VEZNE].[fnMakbuzIslemGetir]
(
@refNo as int
)
RETURNS @tablename TABLE (kontrol1 char(1),key0 numeric(18,0) ,tarih datetime ,hizkod char(12),hizad char(75),ytlhizfiyat decimal(18,2) ,hizmiktar numeric(18,2),ytlhiztutar decimal(18,2))
AS
BEGIN
DECLARE @durum AS VARCHAR
DECLARE @hastaTuru AS VARCHAR
DECLARE @makTipi AS VARCHAR
SET @durum = (SELECT durum FROM TH_RefKart WHERE RefNo = @refNo)
SET @hastaturu = (SELECT HastaTuru FROM TH_Dosya WHERE DosyaNo in (SELECT DosyaNo FROM TH_RefKart WHERE RefNo = @refNo))
SET @makTipi = (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo )
IF ((@hastaTuru = 'Ücretli') AND (@durum = 'AYAKTA')) OR @makTipi = '0'
BEGIN
INSERT @tablename SELECT kontrol1, key0, tarih, hizkod, hizad, ytlhizfiyat, hizmiktar, ytlhiztutar
FROM TH_Islem
WHERE refno= @refNo and DekontNo = '0' and anahtar<> -1
END
RETURN
END
but now I have another problem at this row
SET @makTipi = (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo)
because this SELECT returns multi rows value. what can I do now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,所以 (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo ) 返回多个值,现在做什么取决于你想做什么。 因此,如果您想要这些结果中的最大值,请使用:
或 MIN:
或者稍后使用 @makTipi 来检查某些内容,也许您确实希望保留所有返回的值。 在这种情况下,您需要将 @makTipi 更改为表,并将从 (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo ) 返回的所有值插入其中。 例如:
然后稍后您
将其更改为:
希望这有帮助!
Ok, so (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo ) returns multiple values, what to do now depends on what you want to do. So if you want the maximum value from those results use:
Or MIN:
Or as @makTipi is used later on to check for something, maybe you do want to retain all the values returned. In that case you'd need to change the @makTipi to a table and insert all the values returned from (SELECT maktipi FROM TH_Islem WHERE refNo = @refNo ) into it. Such as:
Then later on where you have:
Change this to:
Hope this helps!
试试这个:
如果所有列都假定为 INT,请进行更改以满足您的需要。
Try this:
WHERE all the columns are assumed to be INT's, change to suit your needs.