Home > Archive > MS SQL Server > December 2006 > Need help with an SQL query and creating Variables for my application??









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need help with an SQL query and creating Variables for my application??
mike11d11

2006-12-13, 12:13 am

Right now I'm filling my dataset by adding a query to my tableadapter
and filling by a specific field value in my ADO.net program. I would
also like to come up with some way to replace the Specific Field "Desk"
in my code and place a variable in there that can be replaced with
anything.

Select * from DataTable Where (Desk = @DeskValue) ' and I name this
query works great.

Select * from DataTable Where (@Field = @Value) 'This doesn't work for
me, but want to know if there is another way to do this?

Uri Dimant

2006-12-13, 5:18 am

mike

Since I don't know your business logic behind it , I can only guess

declare @sql nvarchar(1000),
@col sysname,
@orderid int

select @col='OrderID', @orderid=10248

set @sql = 'select * from Northwind..Orders where '+@col+'= @ordid'
exec sp_executesql @sql, N'@ordid int',@orderid







"mike11d11" <mike11d11@yahoo.com> wrote in message
news:1165985467.864390.301360@80g2000cwy.googlegroups.com...
> Right now I'm filling my dataset by adding a query to my tableadapter
> and filling by a specific field value in my ADO.net program. I would
> also like to come up with some way to replace the Specific Field "Desk"
> in my code and place a variable in there that can be replaced with
> anything.
>
> Select * from DataTable Where (Desk = @DeskValue) ' and I name this
> query works great.
>
> Select * from DataTable Where (@Field = @Value) 'This doesn't work for
> me, but want to know if there is another way to do this?
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com