Stored procedure problem

  • But how do i make this work? All i want to be able to do is declare a list of columns at the start and then use those columns in multiple queries heres my code

    create procedure craigtest

    (

    @postcode varchar(10)=NULL,

    @town varchar(30)=NULL

    )

    as

    declare @columns varchar(300)

    SET @columns='paid, unqueid, initials, firstname'

    select @columns from ifa where town= @town and postcode like @postcode

  • You can't do it that way unless you build up the entire statement and assign it to a string, then run it using Exec(yourstring). This is called dynamic sql. It works, but forces SQL to reevaluate the permissions needed to execute the statement.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply