sql server - How to write a GET SQL Procedure? -


i'm trying make rest api in visual studio 2012 using asp.net mvc 4.

so, right i'm trying make sql procedure , post methods. have little experience sql need help.

( using microsoft sql server management studio )

right i'm trying make procedure tells me values of every row's "a", "b", "c", , "d" columns. helpful method in api, plan loop through number of rows table has!

the problem right sql won't accept select top @counter, accept select top 10 or actual number.

how fix this? also, there easier way of doing i'm trying do? feel not efficient way write procedure simple api.

create procedure gethotticketevent (@counter integer, @a bigint out, @b bigint out, @c varchar(500) out, @d int out)   begin  select top @counter mytable  except  select top @counter-1 mytable  select top  @counter b mytable except  select top @counter-1 b mytable  select top @counter c mytable except  select top @counter-1 c mytable  select top @counter d mytable except  select top @counter-1 d mytable  end 

like this

declare @cnt int = 2 declare @account varchar(1000)  select top(@cnt) @account = col1  ( values ('a',5),                ('k',3),                ('b',8),                ('b',10),                ('a',12) )tc(col1, col2)   select @account --results k 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -