Stored Procedure with Column

This is a discussion on Stored Procedure with Column within the sqlserver-datamining forums in Data Warehousing category; Can a stored procedure be written with a column name? For Table1 with ColA, ColB, ColC, I want a query like: EXEC sp_Mine 'ColA', '100%' I want the results to be like: SELECT ColA, ColB, ColC FROM Table1 WHERE ColA Like '100%' If this is the wrong board, let me know and I'll post elsewhere. I am not an SQL guy....

Go Back   Database Forum > Data Warehousing > sqlserver-datamining

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-08-2008, 04:57 PM
Default Stored Procedure with Column

Can a stored procedure be written with a column name?

For Table1 with ColA, ColB, ColC, I want a query like:

EXEC sp_Mine 'ColA', '100%'

I want the results to be like:

SELECT ColA, ColB, ColC
FROM Table1
WHERE ColA Like '100%'

If this is the wrong board, let me know and I'll post elsewhere. I am not an
SQL guy.
Reply With Quote
  #2  
Old 08-11-2008, 04:17 AM
Default RE: Stored Procedure with Column

Hello

Try with Dinamic SLQ

CREATE PROCEDURE [dbo].[pr_value]
@FIELD varchar(10),
@VALUE varchar(50)
AS
DECLARE @Consulta varchar(2000)


Set @Consulta=
'SELECT ColA, ColB, ColC
FROM Table1
WHERE ' + @FIELD + ' Like ''' + @VALUE + ''''
exec(@Consulta)


--
Ricardo Junquera
Consultor Business Intelligence

BG&S Online Consultores
Ganadora del Premio Microsoft Business Awards 2008.
Partner de Soluciones : Satisfacción de Cliente.



"jp2msft" wrote:

> Can a stored procedure be written with a column name?
>
> For Table1 with ColA, ColB, ColC, I want a query like:
>
> EXEC sp_Mine 'ColA', '100%'
>
> I want the results to be like:
>
> SELECT ColA, ColB, ColC
> FROM Table1
> WHERE ColA Like '100%'
>
> If this is the wrong board, let me know and I'll post elsewhere. I am not an
> SQL guy.

Reply With Quote
  #3  
Old 08-11-2008, 02:27 PM
Default RE: Stored Procedure with Column

Ouch!

Seems simple, but I can complicate it with another question: Is there a way
to make Dynamic SQL work with a custom DataTable that is already loaded into
a DataSet?

My custom DataTable is already a conglomeration of 6 different tables from
our database.

"Ricardo Junquera" wrote:

> Hello
>
> Try with Dinamic SLQ
>
> CREATE PROCEDURE [dbo].[pr_value]
> @FIELD varchar(10),
> @VALUE varchar(50)
> AS
> DECLARE @Consulta varchar(2000)
>
>
> Set @Consulta=
> 'SELECT ColA, ColB, ColC
> FROM Table1
> WHERE ' + @FIELD + ' Like ''' + @VALUE + ''''
> exec(@Consulta)
>
>
> --
> Ricardo Junquera
> Consultor Business Intelligence
>
> BG&S Online Consultores
> Ganadora del Premio Microsoft Business Awards 2008.
> Partner de Soluciones : Satisfacción de Cliente.
>
>
>
> "jp2msft" wrote:
>
> > Can a stored procedure be written with a column name?
> >
> > For Table1 with ColA, ColB, ColC, I want a query like:
> >
> > EXEC sp_Mine 'ColA', '100%'
> >
> > I want the results to be like:
> >
> > SELECT ColA, ColB, ColC
> > FROM Table1
> > WHERE ColA Like '100%'
> >
> > If this is the wrong board, let me know and I'll post elsewhere. I am not an
> > SQL guy.

Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 04:54 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.