Question

I need to do the following:

  1. I already have function with name CONNECT with parameter @table of type table.

  2. I need to assign m2.ID to @c variable, and then select * from result of CONNECT( @c ) function. Variables @a and @b are declared and set earlier.

Code:

declare @c cat;

insert into @c 
  select m2.ID

select 
    m1.nazwa, @a poczatek, m2.ID, m2.nazwa, @b koniec, m3.nazwa
from 
    miasta m1 
inner join 
    miasta m2 on (m1.ID <= m2.ID and m1.ID = @a)
inner join 
    miasta m3 on (m3.ID >= m2.ID and m3.ID = @b)

Edit: I do not know why my code does not appear inside code block.

Was it helpful?

Solution

I do not know what is the type cat you are using to define @c. So are you trying to do something like this?

EDIT: As you have mentioned that cat is of type table, you can insert the ID into the @c variable, and pass that variable to CONNECT function.

Also not sure if a variable of type cat will go with a function with parameter of type table. You might need to update the function CONNECT to take in variable of type cat instead of table. Check the links here

http://www.techrepublic.com/blog/the-enterprise-cloud/passing-table-valued-parameters-in-sql-server-2008/168/

http://www.sailajareddy-technical.blogspot.in/2012/09/passing-table-valued-parameter-to.html

declare @c cat;

insert into @c
select m2.ID
from miasta m1 
inner join miasta m2 on (m1.ID <= m2.ID and m1.ID = @a)
inner join miasta m3 on (m3.ID> = m2.ID and m3.ID = @b)

SELECT * FROM dbo.CONNECT(@c)

If this is not what you need then please elaborate your question.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top