DataSource Controls :: SQL Select Statement - Values To Appear In Same Query
Feb 15, 2010
I am having difficulty selecting data from 2 tables that do no share a primary key value. For instance, I have an actual table, a forecast table, and a GLText table. I may have an actual value but not a forecast value but I need them to appear in the same Query (like the query results shown below). I can get all values to appear in each table but have been unsuccessful in getting all values from both tables.
I have a select statement in a stored procedure and want to be able to retrieve the key column value (PRODUCTID)and return it as Output when Select statement is executed on input Parameter (NAME).
addition, return two further output values (COST,TOTAL).
note the grid control expects to receive all values at once! so i need to get out these values at the same instance of execution.
Select productID,COST,QUANTITY,NAME,TOTAL,DATE FROM PRODUCTS WHERE NAME=@NAME
I have dropdownlist of dates and depending on the date that the user selects from list, I would like to filter records that fall between the startyear and finishyear columns in the datasource. (My the problem is that I do not know how to declare the Startyear and Endyear from the query in the code as they appear underlined - probably the BETWEEN syntax is wrong too).
yYear = DropDownList1.Text Using connection As New SqlConnection("Data Source=CHRIS-PCSQLEXPRESS;Initial Catalog=TorGHL;Integrated Security=True") Dim cmd As String cmd = "SELECT BarDetails.*, MenuHeadingId AS Expr1 FROM BarDetails WHERE (MenuHeadingId = 2)" & "WHERE " & yYear & " BETWEEN " & "(" & StartYear & ")" & " AND " & "(" & EndYear & ")" connection.Open() Dim dapubcb As New SqlDataAdapterDim sqlcomm As New SqlCommand(cmd, connection) dapubcb.SelectCommand = sqlcomm Dim dspubcb As New DataSet("BarDetails") dapubcb.Fill(dspubcb, "BarDetails")
I have a table called 'Customer' that contains customer information. One of the fields is named "CustomerType". Each record in the 'Customer' table will contain the value of either "C", "I", or "O".
I have a form that contains a "check box list" named "Type". There are 3 values in the "check box list". The values are "C", "I", and "O". The user can select one or more of these values. I have a button on the form named "btnRunQuery.
When the user clicks on the button "btnRunQuery" I want to exectute a query that selects the records contained in the "Customer" table where the value in the field "CustomerType" equal the values the user selected in the "check box list". Example: If the user selected "C" and "O", then I want the select query to select all records that contain either "C" or "O" in the field "CustomerType".
I assume that what I need to do is to capture the values that the user selected in the "check box list" and put them in a variable. Then I need to format the "Where" statement in the query and add a "Parameters.AddWithValue" command.
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
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.......
How would you handle an INSERT that gets some values from another table using SELECT, where you wanted some values to come from the source table record and other values to come from a different parameter source like a session value? Is this possible?
I need to create a SELECT statement for a table that excluded the TOP 10 records.
"SELECT TOP 10 field1,field2,field3 FROM AppData ORDER BY field1 DESC" returns the first 10 records from the table but I need to retrieve only from the 21st record onwards.
I simply don't know how to do it because I'm not that strong with SQL. I searched the forum for some answers but can't find a solution that I can understand.
I have SQL Details View insert statement, I need to have a Condition checked for the Insert Query. The condition is, I do have a table by name table1 with the No of Questions (for Eg: 10). The insert statement shud insert data to the table2 (Another table) only if the no of rows is less than or equal to 10 else it shud give me a message (It has exceeded the no of questions).
if I have three Dropdownlist A, B, C, how can I write a select statement to get data from sql server based on the dropdownlist selected.e.g. if user select dropdownlist A, select * from table where A = dropdownlist A but if user select dropdownlist A and C, then select statment is "select * from table where A = dropdownlist A and B = dropdownlist B or if selected A, B, C.......how can I settle so many choice.
I want to select the number of goals, assist and cards a player has in a specific tournament. I tried with this query but then the goal and card column shows the sum of the number of rows matching the playerid in the Goal table and the Card table...For example if there is two matching rows in the goal table and three matching rows in the card table, I get 5 in both these columns in the resultset.
I need to display the table name in the select statement. how?
exact question:
we have common columns in two tables. we are displaying the records by using
select column_name from table_name_1 union select column_name from table_name_2
But the requirement is, we need to display the source table_name along with the data. consider a,c are present in table_1 and b,d are present in table_2. we need the output in the following way
eg: column_name table_name a table_1 b table_2 c table_1 d table_2
Select (datediff(day,db_TargetDate,getdate())) from tbl_abc
in select statement only i wanted only those record in which datedifference is less than 5.
declaration of variable & then conditional checking is not wanted me because i wanted result is into select statement only & not using print statement.
I have a select statement that is supposed to be filling grid with information from an income table. It's only supposed to pull if the income is from the current fiscal year or is less than 1 year old. Currently, what it does is pull multiples of rows and also rows from past income years but only if there is a mixture. For instance, if a person has income from 2005 and 2010 what it will show is this
Income 2005 Income 2005 Income 2010 Income 2010 Income 2010
Does anyone know what I've done wrong? BTW, those results are exact, old income is shown twice, current is shown 3X
Ive been banging my head against the wall for the last 2 days with this query I am trying to produce. I have an application that creates requests and these requests have status codes dependant on how far along in the process they are : new request, awaiting approval, approved, in progress, complete When a request is moved to the next status, it Inserts a row into an auditing table, so we can track who moved it onto the next status, along with a timestamp. There are Service Level Agreements in place that mean that a request that is currently 'In Progress' must be actioned to 'Complete' within 5 days. I have been asked to create a query that will return all records that fall outside of this SLA. My main problem is trying to Select the time from the audit log for 'In Progress' and 'Complete' status codes. It would be simple if i only had to find one of the times, as i could add a "WHERE StatusCode = 'complete' clause to the query My Audit table is structured as follows:
So far I have been successful in querying the table by using the DATEDIFF() function as below:
SELECT DateDiff (day, ( SELECT top 1 CreateDate FROM audit_tblRequest WHERE RequestStatus = 'In Progress' AND RequestID = @RequestID Order by CreateDate DESC) ,(SELECT top 1 CreateDate FROM audit_tblRequestWHERE RequestStatus = 90AND RequestID =@RequestID Order by CreateDate DESC) )
This will return the difference in days to me, however, i cannot figure out how to integrate this into a query that will be run across all RequestIDs. I was wondering if there was any way to bundle the DateDiff function into a stored Procedure and be able to call it For Each RequestID in the result set I would need to pass the requestID as a parameter, and also add some If Else logic to only return records outside of the 5 Day SLA. Im sure there are some patches in the above logic, but my brain is about to explode and I needed to type it all out before calling it a day for today.
This question is for wrapping up work on a database driven AJAX AutoComplete Control that I am using to provide keyword hints to user on search pages. Each record has 6 columns for keywords where each column is for an advertiser to add a keyword. These are used in meta keywords tags, but I also want to use them for AutoComplete. The problem is that I don't know how to write a SELECT statement in Visual Studio that treats all 6 keyword columns as if they were all one column. I am looking for something like
SELECT (keyword1 + keyword2 + keyword3) AS Keywords FROM (Merchandise) WHERE Keywords LIKE @term
The only other thing I can think of the gain this level of functionality would be to combine them into a new table.
Im using SQL Server 2005 and im using stored procedures. Is this possible? i need to get a number of results and do it in one SELECT statement or just one result set. Im using MS Chart Controls for reporting and they cant seem to process multiple result sets this is my problem, so basically to run a barchart i need to assign a column to the X axis and a column to the Y axis and it will then display my results.
My stored procedure below returns a result set with columns subpolicy_name, building_name, floor_name, room_name and total_savings. Im just wondering is it possible to split my total_savings column into 4 columns, for example subpolicy_savings, building_savings, floor_savings and room_savings, i need everything in a separate column. If you run this stored procedure you will see the result set.