2010-08-10 10 views
5

में टेबल वैरिएबल पास करना मुझे एक गतिशील एसक्यूएल चलाने की आवश्यकता है जो अभिभावक के दायरे में बनाए गए तालिका चर का उपयोग करता है। SQL2008 में मैं गतिशील एसक्यूएल में टेबल वैरिएबल कैसे पास करूं?गतिशील एसक्यूएल 2008

+0

अपने प्रश्न की सामान्य प्रकृति, शायद आप गतिशील एसक्यूएल पर यह सामान्य प्रदर्शनी द्वारा अच्छी तरह से सेवा की हो जाएगा देखते हुए? http://www.sommarskog.se/dynamic_sql.html – Tobiasopdenbrouw

उत्तर

18

यहाँ एक अंत अंत उदाहरण है:

-- Define a custom TABLE type 
CREATE TYPE IntegerTableType AS TABLE (ID INTEGER); 

-- Fill a var of that type with some test data 
DECLARE @MyTable IntegerTableType 
INSERT @MyTable VALUES (1),(2),(3) 

-- Now this is how you pass that var into dynamic statement 
EXECUTE sp_executesql N'SELECT * FROM @MyTable', 
    N'@MyTable IntegerTableType READONLY', 
    @MyTable 
+0

जो जल्दी था! बहुत बहुत धन्यवाद –

संबंधित मुद्दे