Re: need some advise
From: Keith Kratochvil (sqlguy.back2u_at_comcast.net)
Date: 08/11/04
- Next message: Aaron [SQL Server MVP]: "Re: Output parameter with SP"
- Previous message: zeyneddine: "Update statement if field is NULL or empty"
- In reply to: Simon Whale: "need some advise"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 11 Aug 2004 09:31:08 -0500
I would opt for creating a stored procedure and executing that. This will
allow you to change the stored procedure if necessary without having to
recompile your code. Another benefit with this method is that you have the
ability to use that same sql code elsewhere (simply by calling the stored
procedure).
--
Keith
"Simon Whale" <simon@noway.ukdatait.com> wrote in message
news:OhYNi46fEHA.2352@TK2MSFTNGP09.phx.gbl...
> Hi all,
>
> need some advise on the best way to do something, i have written a script
> that i want to execute from an application that i am writting using
ado.net.
>
> the script is below i know that i need to change the script to pass the
info
> back to the progam, but what should i set this script as function? stored
> procedure? or just execute the script?
>
> i would be grateful for any comments
>
> Many thanks
> Simon Whale
>
>
> ---SQL Script
> --variables
> declare @name varchar(50)
> declare @out varchar(50)
> declare @found int
> declare @sfound varchar(2000)
> declare @s varchar(2000)
>
>
> set @found = 0 --sets a flag if any have been found
> set @out = '' --used to retrieve numerb from tables
> set @sfound = ''
>
> declare db cursor for
> select name
> from sysobjects
> where xtype = 'u' and patindex('%[a-z][0][0-9][0-9]',name) > 0 or name in
> ('tps_ns','ctps_ns','fps_ns') or name like 'silent%'
>
> open db
> fetch next from db into @name
>
> while @@Fetch_status = 0
> begin
> declare @sql nvarchar(2000)
> set @sql = 'select @out = col001 from ' + @name + ' where col001 = ''' +
> @cli + ''''
> exec sp_executesql @sql, N'@out varchar(50) output', @out output
>
> if @out <> ''
> begin
> set @found = @found + 1
> set @sfound = @sfound + @name + ';'
> end
>
> fetch next from db into @name
> set @out = ''
> end
>
> close db
> deallocate db
>
> if @found = 0
> begin
> set @found = 'No Matches Have Been Found'
> end
>
> print @found
>
>
>
- Next message: Aaron [SQL Server MVP]: "Re: Output parameter with SP"
- Previous message: zeyneddine: "Update statement if field is NULL or empty"
- In reply to: Simon Whale: "need some advise"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading