DataSource Controls :: Display The Table Name In The Select Statement?
Feb 23, 2010
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
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.
the select statement for my gridview contains a sub select statement..that should allow users to see how many queries are associated with a particular record..how can I get the queries column to display in my grid. As it is a count and not directly bound to any field
SELECT WardID, ScriptID, DateAdded, (SELECT COUNT(scriptID) FROM query WHERE scriptID = main.scriptID) AS queries.......
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 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 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 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.
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.
I am new to all this, and ignorant beyond compare. I believe I have the same problem as this :
[URL]. However, the solution proposed for him doesn't seem to work for me. I have a session variable that 'march_cpi_session' that I wish to include in an sql select statement to multiply the values I get from a datatable before they're used to populate a gridview control. The session variable works fine elsewhere in my application, but causes a variety (depending upon how I fiddle about with the syntax) of sql errors. This is the currrent code:
I'm facing a problem in our current running application. There is a table in database which has 67 columns,among these 18 columns are nvarchar(max) datatype and contains 30K records. Problem is now that SELECT * FROM myTable it takes around 3 to 4 seconds. Which is degrading our application's performance.