我在這裏有一個挑戰,我有一個表叫fileTable
有以下欄目:返回兩個項目的字段和值從SQL Server功能
FileID FileName
=================
1 | sdk
2 | mdk
3 | jdk
4 | apk
我在這裏的挑戰是編寫得到了功能通過文件名,如果它確實存在於表中,則返回值1和其fileID,如果不返回值0和ID 0
現在,我已經開始了,我想把它作爲一個表但是當試圖使用聲明或者函數內部的語句時卡住了
ALTER FUNCTION [dbo].[booker](
@filenumber nvarchar(50))
RETURNS TABLE
AS
RETURN
(
--NB
-- note the challenges am facing i thought of passing a value of FileID to @fn then check if its empty or not, that wont work
--- Declare @fid int; // is not accepted inside here
-- IF EXISTS (SELECT @fid=FILENUMBER FROM [dbo].[File] WHERE FILENUMBER = @filenumber) // the if statement is wrong here too
SELECT FileID
FROM [dbo].[File]
WHERE FileID = @filenumber
-- am left with the above statement where i can extract the FileID but don't know how to check if it exists and if so how to
-- return it with a value 1 that shows the record is in and value 0, fileid=0 if there is no record
)
爲什麼你需要帶表格? – Viki888