all groups > sql server programming > august 2007 >
You're in the

sql server programming

group:

Odd SQL Server Stored Procedure Question


Odd SQL Server Stored Procedure Question Mandoskippy
8/11/2007 7:22:54 PM
sql server programming:
I am trying to run a stored procedure that allows me to use a various
as the "as" portion... A simple example is as follows:

CREATE PROCEDURE dbo.prTest
AS
DECLARE @Test1 varchar(10)
DECLARE @Test2 varchar(10)

set @Test1 = 'Data'
set @Test2 = 'Column'


select @test1 as @Test2
GO


Now this is just an example of the issue... anyone have an idea of how
to go about this? the column names are important in this setup. I
would prefer not to hard code them if possible.
Re: Odd SQL Server Stored Procedure Question --CELKO--
8/11/2007 8:30:46 PM
[quoted text, click to view]

So you have no idea what data you are fetching and no idea what you
want to call it until run time??!! This is what I call the
"Automobiles, Squids and Briteny Spears" model of programming.

If the column names are truly important, then they will well-defined
according to ISO-11179 rules and in your data dictionary. The data
dictionary will be shared across the entire enterprise from SQL to
COBOL to whatever the "Le app language du jour" is this month.

Your problem is not SQL programming; you don't know anything about
basic software engineering.
Re: Odd SQL Server Stored Procedure Question Steve Dassin
8/11/2007 10:24:49 PM
[quoted text, click to view]

And this model of programming is precisely what modern day developers
should be following! This model of programming gives rise to the
'super function'. To understand the concepts involved and see its use and
understand why people (Joe) invent non-sense to inhibit its adoption and
maintain the same programming model as Cobol see:

http://beyondsql.blogspot.com/2007/08/dataphor-creating-super-function.html

It's also a chance to contrast the idea of a table as a variable, 'any'
table,
with the mickey mouse idea of passing a table 'memory' variable as being
implemented in Katami. We are talking apples and oranges folks :-)


Re: Odd SQL Server Stored Procedure Question Steve Dassin
8/11/2007 11:13:35 PM
See my reply to Joe.

www.beyondsql.blogspot.com

Re: Odd SQL Server Stored Procedure Question Tibor Karaszi
8/12/2007 12:00:00 AM
You can use dynamic SQL:

DECLARE @sql nvarchar(4000)
SET @sql = 'SELECT ' + @test1 + ' AS ' + '@test2'
EXEC(@sql)

I strongly suggest you first read the article on dynamic sql at www.sommarskog.se.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi


[quoted text, click to view]
Re: Odd SQL Server Stored Procedure Question Sylvain Lafontaine
8/12/2007 8:00:31 PM
"Le language d'application du jour", not "Le app language du jour".

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


[quoted text, click to view]

Re: Odd SQL Server Stored Procedure Question Sylvain Lafontaine
8/12/2007 8:05:19 PM
Or even better: "Le langage d'application du jour"; without the letter u for
"language".

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
[quoted text, click to view]

AddThis Social Bookmark Button