关注var mongoose = require('mongoose');
var studentNames = new mongoose.Schema({
firstName: {type: String, required: true},
lastName: {type: String, required: true},
telephone: {type: String},
emailAddress: {type: String},
isMember: {type: Boolean},
lessons: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}]
});
var lessonNames = new mongoose.Schema({
name: {type: String},
startTime: {type: String},
endTime: {type: String},
day: {type: String}
});
var locationNames = new mongoose.Schema({
name: {type: String, required: true},
address: {type: String},
lessons: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
lessonDays: [{
Monday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
Tuesday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
Wednesday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
Thursday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
Friday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
Saturday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}],
Sunday: [{type: mongoose.Schema.Types.ObjectId, ref: 'lessonnames'}]
}]
});
mongoose.model('studentnames', studentNames);
mongoose.model('lessonnames', lessonNames);
mongoose.model('locationnames', locationNames);
我写了哪个接受function
并返回xml
作为结果。
table
以下是我用来对CREATE FUNCTION FunctionTest(@ID INT,@XML_Details xml)
RETURNS @RESULT TABLE
(
Value1 INT,
Value2 INT
)
AS
BEGIN
DECLARE @tbl_Xml_Result Table
(
Value1 INT,
Value2 INT
)
INSERT INTO @RESULT(Value1,Value2)
SELECT
l.v.value('Value2[1]','INT'),
l.v.value('Value1[1]','INT')
FROM @XML_Details.nodes('/Listings/listing')l(v)
RETURN
END
上面运行的代码,但它始终返回function
结果。
Empty
答案 0 :(得分:3)
首先,尽可能避免多线功能。 Inline UDFs have better pefromance
第二个XQuery
区分大小写,并且您没有'/Listings/listing'
路径。
第三:您可能希望使用@ID
进行过滤。
CREATE FUNCTION FunctionTest(@ID INT,@XML_Details xml)
RETURNS TABLE
AS
RETURN(
SELECT Value1, Value2
FROM (SELECT
l.v.value('(Value2)[1]','INT') AS Value2,
l.v.value('(Value1)[1]','INT') AS Value1
FROM @XML_Details.nodes('/Listings/Listing')l(v)) AS sub
WHERE Value1 = @ID
)
GO
DECLARE @tbl_Xml_Result Table(Value1 INT,Value2 INT);
INSERT INTO @tbl_xml_Result(Value1, Value2)
values(1,2),(2,3),(3,4),(4,5),(5,6);
DECLARE @xml_Temp xml = (SELECT *
FROM @tbl_xml_Result
FOR XML PATH('Listing'),ROOT('Listings'));
SELECT T.Value1,
T.Value2
FROM FunctionTest(1,@xml_Temp) T;
的 LiveDemo
强>
答案 1 :(得分:2)
你职能第19行的问题:
FROM @XML_Details.nodes('/Listings/listing')l(v)
* l 正在努力 - 您需要 L 正在努力