I thought this would be easy but cannot now find out of to do it. All I want to do is execute an sql query on a table and in addition to the table's columns I want to also select/output a field that is calculated within the query. The table has a column "Owner" and I want to compare this to the UserId to produce a bool column "mine". Effectively doing:Select *, (Owner=@UserId) as mine where.....however, this doesn't work so how can I calculate a column in the select statement?
At the top of my form I have some code that calculates a field
[Code]....
In my form I have this code. What changes below do I need to make to have the value of Date in XXXX?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqlConnection %>" SelectCommand="SELECT NumPeople, Date1,Time1,Venue FROM People_Count WHERE ((Date1=@ArvDate and Time1 >= '06:00:00.000') or (Date1=XXXX and Time1 <= '06:00:00.000')) and Venue='F & B' ORDER BY Date1 ASC, Time1 ASC"> <SelectParameters> <asp:QueryStringParameter Name="ArvDate" QueryStringField="ArvDate" /> </SelectParameters> </asp:SqlDataSource>
although i had to take the table that has my calculated column and make a view (so i could filter) and then bind the gridview to the view.
My question is as this.
1.) in order to get my calculated field i had to load my data into a table (as suggested)
2.)Add a column to the table and perform calculations
3.)make a dataview from the tables because i could not get the Gridview.datasource= ds.tables("loads").select("Deadhead <= " & sngRadius
4.)the largest of the 3 tables my query is based on contains about 7000 records. The way i have the logic & programming now everytime a new "truck location" is put in the textbox1 and "find loads/button1" is clicked. It calculates the deadhead miles of all 7000 records before filtering. I am filtering based on the deadhead miles.
Does anyone have any recomendation about how to speed this up a bit.
Also in order to get paging to work i had to rebind/filter the data again ... means looping through all 7000 records each time paging is called. This seems terribly ineffecient as i am already forced to use access instead of SQL.
Would i see a performance increase if i installed SQL or mySQL and create linked tables to the ones i use in access. or would access still be the bottleneck?
I don't know if the performance increase would be negligible as i still ultimately be getting the data from Access.
I have posted the entire code for the page below. When i originally started i didn't think there would be to much code so i left it all on one page instead of using code-behind. Would i gain anything by swapping to code-behind now?
I have a simple query on a table to calculate the sum of a field (This field is a calculated field from within SQL 2005)SELECT SUM(RunTime) AS TotaL FROM TimeSheets.It errors out with: Error Message: Operand data char type char is invalid for sum operator.If I use the MAX or MIN function, no isssues. The data in this field is numeric.
I'm using a gridview to extract a set of records. I need to add another field to the gridview, which can calculate the difference between a date associated with each record and the current date.
How would i make a select statement select the row with the nearest values? e.g.: I have 3 labels, labels1 2 and 3, with values of 1.2, 2 and 5.8 In my table i have 4 columns, first is the data im after, and the next 3 relate to the three labels. I want to select one row, where the values of labels match it the closest.......
1.LookupPageInfo and (LookupPageInfoId,pathmessageID,pagemessageID)
2.Messages (MessageId,MessageText,ChannelID)
Now i need to write a query something like this........in the query i need to pass the pathmessageid and needs to get messagetext from Messages Table,i am not sure how i need to write the below query..can someone guide me how can i write a query......as below..
select LookupPageInfoId, PathMessageID, pagemessageID, (select messagetext from Messages where MessageID=PathmessageId) as TEXT from LookupPageInfo
I have two dropdown list, which is 'names' and 'types' and it's being populated by a dataset. It contains an additional item "-- ALL --" to indicate that all items of a particular field are being shown. I have an SQL select statement to filter the records according to the selected item of the dropdowns. I used a select statement to bind the records to a datagrid with regards to the selected items.
SELECT * FROM table where name = ddlnameselecteditem AND type = ddltypeselecteditem
The problem now is when I select a name from the names dropdownlist and types dropdownlist has a selection of -- ALL --, there would be no return records because there's no such thing as '-- ALL --' record in column 'types' i'm querying. I need to display rows of the selected 'name' while still showing all the 'types'. How could I achieve this? I think I need to avoid the '-- ALL --' item from the dropdownlist.
I'm pretty new at ASP. I've got a sheet I'm trying to modify using an IF statement. I tried putting them in, in different ways, but it either shows up in the form or I get the options multiple times
[Code]....
i have a variable picked up elsewhere strArea, so I was trying to do something like
[Code]....
I have tried putting the if's in different places, as well as case statement but usually I end up with my drop down option list as 1 1 2 1 2 3
I'm trying to pull a list of clients that have both of two codes in the code table. Here is what I have tried and it does not return any rows. I know that there are clients that have both codes.
I have records in the datatable which I have retreived from xml file.
Dim docDataSet As New DataSet Dim docReader As New XmlDocument Dim xnl As XmlNodeList docReader.Load("UserProfile.xml") xnl = docReader.SelectNodes("/Users/user") For Each xn As XmlNode In xnl Dim xr As New XmlNodeReader(xn) docDataSet.ReadXml(xr) Next xn Dim Dm_table As DataTable = ds.tables(0)
Now what I want to do is execute a select query like below:
Select * from user where userid in (select ID from Dm_table)
Retreive the records from the User table based on the ID's in the datatable.
I have to pull up a list of people by their branch number which could vary, and give a detailed report on there performance using a select queries. I have the select queries but how can i create a script to look similar to this one. Ive got the branch drop downlist already created just need to know how i can go about pulling all the users in this group and doing this select to all of them. someone told me I might need to use cursors to loop thru a select with every person in the list but im not sure how to go about that.
select fldusername from tbluser where fldio='o' and flduserbranch=@branchid
is going to give me the names of the people i need to query. but how can i run a query on each of them seperate?
Here is the deal. I need to create a Stored Procedure that has 2 SELECT statements. Now in ASP.NET, I know that a DataSet can have multiple tables and the DataAdapter can do just that. I am stuck with a scenario where I need to get a value from the first SELECT statement which will later be used in the second SELECT statement. I am creating a SP that passes one parameter (@AnswerID). Which should give me 2 resultsets. See below SELECT statements.
[Code]....
So how do I get the QuestionID from the first SELECT statement?
Basically I am creating a Questionnaire that has Question Dependacies. So from the above SQL statements I would like to display the Question Title with it's relevant answer options but depending on the previous Answer selected hence the @AnswerID parameter.
The reason why I want to use 2 SELECT statements is because I don't want to have 2 roundtrips to th server. So in my code the DataAdapter should return 2 resultsets and fill the DataSet.
If there is any another solution that can prevent 2 roundtrips to the server, I would most definitely like to know how to do it.
Unfortunately, I get the following error message:Message="The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified."
I am using join to get values from three tables. I want the first column to be Sl.No which autoincrements by 1.What should i write in the select for the first column.
this might be an easy one, but I just can't get it.I am creating a page which will query a table with many columns and most items are not unique. I need to be able to get a list of records that match as many of the (up to 4) search criteria as possible.Example:am user searching for the following items, I enter at least one and up to 4 of the items below in a text box:Name, age, gender, weight (user may or may not fill in all of them).If he just enters "F" for gender, then he will get a list of thousands of females with their name, age, gender and weight.However if he enters "F" for gender and "300" for weight, he will get a much smaller list of returned records.I need to be able to create a sql statement that can perform that search with that functionality.