| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
|
| 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. |
|
#2
|
| 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. |
|
#3
|
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |