DataSource Controls :: Using Varibale In The Where Clause?
Apr 21, 2010
I am having difficulties using a variable in the "where" clause:
declare @shift_started as datetime
set @shift_started = (SELECT *
FROM OPENQUERY(ADS_RGWP_SERVER, 'SELECT MAX(shift_started) as shift
FROM salestkt AS STK
WHERE NOT EXISTS(SELECT *
FROM SHFTDATE AS SD
WHERE SD.shift_started = STK.shift_started)'))
SELECT *
FROM OPENQUERY(ADS_RGWP_SERVER, ' sum(case when customer_type = ''Inter-Company'' then qty_shipped_today else 0 end) as intercompany_qty,
sum(case when customer_type = ''Charge'' then qty_shipped_today else 0 end) as outside_qty
FROM salestkt
WHERE shift_started ='" & @shift_started & "' ''')
i am developing an application using asp.net and backend server is SQL SERVER 2005.
in my application i have 12 regions. from that 12 regions user will select any of them.
if user select 1,2,3 then i have to pass this string to IN clause
for that i have storedproc like
create procedure sp_updateDistributorContractforAllRegions ( @unitprice float, @region varchar(50) ) update employee set UnitPrice=@unitprice where regionid in (@region) end GO
here regionid datatype in employee table is INT.
from code behind i am adding the parameter as 1,2,3.when i run the query it gives the error as
Conversion failed when converting the varchar value '1,2,3' to data type int.
I have an SqlDataSource query that should use an input parameter for multiple integer values, like:
select * from table1 where TableID IN (1,2,3,4,5)
->
select * from table1 where TableID IN (@IDValues)
How do I do that ? Default parameter settings won't work, returning "invalid integer value" . I suppose that parameter should be passed as some kind of array that SQL recognizes as multiple integer values , but what's the correct way of setting this ?
SELECT DISTINCT TblSections.SectionID, TblSections.Description FROM TblSections INNER JOIN UMG.Users ON TblSections.SectionID = UMG.Users.SectionID WHERE (TblSections.Description IS NOT NULL) AND (dbo.Users.LoginName = [@Session(UserName)]) ORDER BY TblSections.Description
I have problem in using Session name in the above BOLD WHERE clause.
I have a GridView that's currently bound to an ObjectDataSource. I would like to see if it's possible to instead bind it to an EntityDataSource. However, I need to be able to apply custom filters to it.
One of the filters corresponds to a bit / boolean property in the database / EntityDataModel. It has 3 possible selections:
[Code]....
[code]....
How can I accomplish the same thing in an eSQL Where clause? There is no COALESCE function, is there an equivalent?
I've already spent hours in searching through the forum to be able to do the following:I have a SQL datasource defined with a checkbox in it. Purpose is to update one column (userid) behind the table for only that row when the checkbox is selected.This is the code I'm currently having:
I am using Linq to SQL. Tables have timestamp columns and I am using regular Linq methodology in ASP.NET MVC.I do use detached entities and always try to do updates without first querying the database for the original entity. To update an entity I use context.Attach(entity, true) followed by context.SubmitChanges() and all is fine. The sql statement that gets executed looks like:
Ive created a new LINQ To SQL class and dragged several tables across from my server, in my code I access them like this
[Code]....this is all ok, however, I have several stored procedures that I want to use as well, but when I drag the stored procedures across I get a compilatiopn error
Error 60 'DB_BL.DB_BLDataContext': type used in a using statement must be implicitly convertible to 'System.IDisposable'
how do I use stored procedures from LINQ with a using clause ?
I have some duplication that I need to clean up. I wrote a SQL query that is supposed to return duplicate customers who are located in the same city and zipcode.
I have 2 questions regarding it:
1. Is the query syntax correct to find duplicate records by same city and zipcode, data is being returned but it just returns the same customer a few times?
2. I only need to do the GROUP BY clause for Fullname and City however it gives an error when the other columns are left out. The error is Address, State and Zip not being in the aggregate function or in the group by clause.
Adding all the remaining columns to the GROUP BY clause works.
I know I'm missing something here but I can't figure out what it is. I've got a query joining three tables....accounts, payments, and a table linking the two (there is a M:M relationship).I'm trying to pull a list of all accounts in the account table that have a payment that needs to be resequenced, and also the maximum payment priority if there are any payments that haven't been fully paid. If all payments HAVE been fully paid, I want to return a 0.
It's that last bit of logic that I can't get right. If I include that in the where clause, I get only the accounts that have a payment that hasn't been fully paid. If I take it out, I get all the accounts I get, but I get the highest payment priority whether or not the payment has been fully met.
Here is the query....how do I include the where clause criteria but still include all accounts?
I'm having trouble writing what should be a simple sub-query using LINQ to Entities. I have two tables: Customers and Orders that have a relation on the CustID field. Not all Customers have a record in the Orders table, while some have mutiple records. In traditional SQL, you could write the query like this: SELECT * FROM Orders where CustID IN (SELECT CustID FROM Customers) I know this could be done as a JOIN in both SQL and L2E, but my actual query is more complex (about 8-9 joins), so I am hoping to find a L2E sub-query equivalent. Something like this:
[Code]....
I know LINQ to Entities does not support the " IN " clause, so I am looking for something that will work in its place.
Here is a button inside a listview that is using the LinqDataSource and also has a pager:
[Code]....
And here is the Code Behind that is triggered by the linkbutton:
[Code]....
It almost works. When i click it it loads and shows the current page of objects that have dates that are higher then todays date. Which is what i want. But as soon as you use the pager to go back or forward it reverts to the default, which is ALL articles, sorted by ID. How can i make the "where" selection stick through the paging?
Iīm a newbie at .NET and Iīm trying to solve how to run a datagrid with parameters. I know how to do where clauses with controls and today I managed to solve how to have a where clause at UserID within a SelectingEvent.BUT, I canīt run them both in the same time. I want to run a query based on the month in a dropdownlist and the UserID. Each one individually works.Why canīt this be done? Is the onselect statement ignoring the other parameter? I donīt get any errors.The ASPX (in VB.net) code is:
I am fairly new to Visual Web Developer so I hope this makes sense.I have a page with a GridView (code below). When a person clicks on the Select Link, I would like it to direct them to a page with a FormView of the selected row so that it can be edited. I feel that this should be fairly basic but am having trouble finding the means to make it happen.
CustomerService service; public CustomerService Service { get { if (this.service == null) { this.service = new CustomerService(); } return this.service; } } public DataTable GetCustomers() { return this.Service.GetCustomers(); }
Now the question is: if I wrote the above method as follow (without "this"), it's giving me an error : instance is not reference to an object.
public DataTable GetCustomers() { return Service.GetCustomers(); // this will spell the error "instance is not reference to an object" }
Does anyone know? also it only happens while running via IIS and not from casini web server (VS 2010).
I have a query with group-by clause. I want to use it in recusionCTE.How is it possible?I want to know the totalamount for each fname done through this query:select top 10 fname,SUM(totamt) as 'Total Amount' from tables_list group by fname order by 'Total Amount' descBut when any person logins he must be able to see this list for his own hierarchy down the line including himself.
I'm working on an MVC 2 website, with LINQ. I have the following section to handle updating my Photo object.
[Code]....
In this case, only the field Title changes. But I'm wondering why the WHERE clause isnot simply WHERE PhotoId = @p0... because PhotoId is the primary key. Is there anything I need to do when mapping or something to get the WHERE clause that I expect?
I'm working on asp.net web application & for this use MS access for back end, My Query is given below which is successfully executed on MS Access but error on front end ("Syntax Error in FROM Clause")
select USER.EMPID as EMPID,USER.FULLNAME as FULLNAME, USER.USERNAME as USERNAME,Employee.ROLEID,ROLE.ROLENAME AS ROLE FROM USER inner join employee on user.userid=employee.userid inner join role on employee.roleid=role.roleid WHERE USER.EMAIL='admin@itiersolutions.com' AND USER.PASSWORD='cZdqAEeDV2EVzA1JNFJ6hQ==' AND USER.STATUS='Enable'