.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to extend this query to write the results back to a database?

Posted By:      Posted Date: September 12, 2010    Points: 0   Category :Sql Server
FOr this query I have four tables I would like to access. SELECT StockA, SUM(Score) AS Total FROM dbo.ScoresNew_LongPrice WHERE [When] >= @StartTime AND [When] < @EndTime GROUP BY StockA ORDER BY SUM(Score) DESC _LongPrice, _ShortPrice, _LongVolume, _ShortVolume I would like to improve the above query to return not just the results from LongPrice, but four columns, of sum(score), from each table, if possible. And, if that is possible, I would also like to have the query then update another table with its results.  Not a new table, but just updated to an existing table. Anyway, I can do some stuff in T-SQL but this seems over my head.  Any help would be appreciated. (The four tables all have identical structures)

View Complete Post

More Related Resource Links

Write select query with a paremetrized where clause, and populate database with the retrieved column

I want to be able to retrieve column values using the dropdownlist values as parameters then populate the tbPO table with the retreived values. Where and how do I do it. ImportsSystem.Data.OleDb ImportsSystem ImportsSystem.IO Imports ?directcostDataSetTableAdapters PartialClass po_header  Inherits System.Web.UI.Page  Dim cn As OleDbConnection  Dim cmd As OleDbCommand  Dim dr As OleDbDataReader  Dim icount As Integer  Dim str As String  Dim vendor_id As Object   ?  Public Sub btn_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.ClickTry   context.Items.Add(     cmd.CommandType = System.Data.   cmd.CommandText = Dim context As HttpContext = HttpContext.Current"Company_Name", DropDownList3.Text)Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\Owner\Documents\Visual Studio 2010\WebSites\WebSiteJun25\App_Data\directcost.mdb;")Dim cmd As New OleDbCommand()CommandType.Text"insert into tbPO(ponumber, suppliername, ShipTo, basictype, DateNeeded, Purpose,ShippingInstr, ProjId) values(?,?,?,?,?,?,?,?)" cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.AddWithValue( cmd.Parameters.Add

get the last inserted row ( autoincrement id ) in mysql database back


In my mysql I have an autoincrement id , whenever I add a new row into database I need to store this id in other table, so how to get this autoincrement Id back?

Linq query results to List collection



I have a GridView in my page. I want to use below code in code beind. query nothwing DB using linq . add linq query result to new list and then bind list as gridview Datasource

I use below code . But I don't know how to add results to List? Could any one tell me how !

Public Class OrderCity
        Private _name As String
        Private _city As String
        Public Property name As String
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value

            End Set
        End Property
        Public Property city As String
                Return _city
            End Get
            Set(ByVal value As String)
                _city = value

            End Set
        End Property
    End Class
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim dbe As New SFFAV1DataContext
        Dim latestadsDs = From p In dbe.Products _
                            Select New With {p.Title, p.ProducedCity} _
                             Take (2)

        Dim FilteredList As New List(Of OrderCity)()
        For Each result In latestadsDs
            Dim Menedfcou = Nothing
            FilteredList.Insert(0, Menedfcou)

Errors in the back-end database access module. OLE DB reported an overflow of the data type for colu

Getting an error when processing a dimension, Errors in the back-end database access module. OLE DB reported an overflow of the data type for column 0. Errors in the OLAP storage engine: An error occurred while the 'xxxxxx' attribute of the 'Dim XXXXXX' dimension from the 'XXXXXXX' database was being processed. Content of this dimension is very similar to one that is processing no problem. The content of the dimension is one field only of type date.  The original content was imported through SSIS from a DB2 database on an iseries machine.  Thought a first the issue was because of the data contains some null values but the dimension the process OK also has some null  values.  The dimension that processes ok is also a single field of type date. Any help greatly appreciated, Roscoe

How to write the LINQ query for the following

Hello All, I have an entity type with the following properties: UnitId, UnitDescription, ParentId, EffectiveDate - (Say the entitty type is Unit)  I want to filter out a list of UnitIds whose effective date is less than a given date. But since there could be many EffectiveDate s less than a given date, I want to take the latest one(Max). Simply told, I want to get the unit ids with the most recent effective date prior to a given date. How can I do this in a single linq statement? Appriciate any help.

E-mail query results

I have the following piece of code that returns nothing when there is only one row that fits the criteria. If there are two or more rows that match the criteria it works. Any idea what is wrong?? Declare @drugID varchar(4000),@lineresult varchar(4000), @SEND VARCHAR(256), @RECP VARCHAR(256), @TITLE VARCHAR(256), @BODY VARCHAR(4000), @SERVERNAME VARCHAR(256) set @drugID = '' declare r_cursor INSENSITIVE CURSOR FOR SELECT AHI_DRUG_DOSE.Drug_Display_Name+ ' ' +convert(varchar(10),AHI_CAB_EVENT.Station_Id)+ ' ' +convert(varchar(25),AHI_CAB_EVENT.Event_Dttm)+ ' ' + AHI_CAB_EVENT.Event_Type+ ' ' + convert(varchar(10),AHI_CAB_EVENT.Trans_Qty)+ ' ' +convert(varchar(25),AHI_CAB_EVENT.Site_Patient_Id)+ ' ' +AHI_CAB_EVENT.Pat_Name+ ' ' +AHI_CAB_EVENT.Misc1 FROM AHI_DRUG_DOSE AHI_DRUG_DOSE INNER JOIN CRX_DATA.dbo.AHI_CAB_EVENT AHI_CAB_EVENT ON AHI_DRUG_DOSE.Drug_Dose_Id = AHI_CAB_EVENT.Drug_Dose_Id WHERE (AHI_CAB_EVENT."Station_Id" = 'OPS' OR AHI_CAB_EVENT."Station_Id" = 'OR1' OR AHI_CAB_EVENT."Station_Id" = 'OR2' OR AHI_CAB_EVENT."Station_Id" = 'PACU') AND AHI_CAB_EVENT."Event_Type" = 'WASTE' AND AHI_CAB_EVENT."Misc1" <> 'Partial Dose' AND AHI_CAB_EVENT."Event_Dttm" >= get

Cube Writeback SQL Server 2008 R2 (SSAS, write back)

CUBE WRITE BACK in SQL SERVER 2008 R2 Did anybody get the SSAS write back functionality to work against a decent sized datawarehouse? I'm not asking about a little demo but a significant sized footprint e.g. 14M Rows measures, 6-8 wired Dimensions with 8-10 attributes each. I setup a test server using a Dell XEON ( 2x4core) with 48 GB RAM hardware and the latest Sql Server 2008 R2 release. I used the What-If scenario in Excel 2010 and modified a higher level, hoping SSAS would push the values down. After about 15 minutes and after having used 48 GB memory (on average 5% CPU) Excel throw an error - short on memory - and stopped the action. I found the same behavior in Sql server 2005 and 2008 and was hoping this would work now but apparently not so. Here are my questions: Is anybody using this at all? how can one calculated (roughtly) how much memory is requiered? is there any paper that describes best practise? Thanks for any help in advance, Dirk  

How to write query with subquery more efficient

Hello, I have this query which generates sick days. I have a sick start date and end date, and by joining it with a date table I get all sick days for each employee. But as you can see i select a number of fields, but in the subquery i select a number of fields which are the same. Is it possible to write it more efficient? Thans in advance! SELECT z .ziekmeldingID, z .hrmID, z .ZiekStartDatum, z .ZiekEindDatum, z .ZiekStartTijd, z .ZiekEindTijd, z .ZiekOpen, z .ZiekTypeID, z .ZiekRedenID, z .ZiekStart_KEY, z .ZiekEind_KEY, z .Verzuimduur, D .Datum AS ZiekDag,   CAST(CONVERT(char(8), D.Datum, 112) AS int) AS ZiekDag_KEY, z .hr301_date, z .PercentageZiek, z .PercentageHersteld FROM     (   SELECT dbo .hr300.hr300_obj AS ziekmeldingID, dbo .hr300.hr300_date_start AS ZiekStartDatum,   CASE   WHEN dbo.hr300.hr300_date_end IS NOT NULL   THEN dbo.hr300.hr300_date_end   ELSE getdate()   END AS ZiekEindDatum, dbo .hr300.hr300_time_start AS ZiekStartTijd, dbo .hr300.hr300_time_end AS ZiekEindTijd, dbo .hr300.hr300_open AS ZiekOpen, dbo .hr300.hr104_obj AS ZiekTypeID, dbo .hr300.hr038_obj AS ZiekRedenID, dbo .hr300.hr200_obj AS hrmID,   CAST(CONVERT(char(8), dbo.hr300.hr300_date_start, 112) AS int) AS ZiekStart_KEY,   CAST(CONVERT(char(8), dbo.hr300.hr300_da

Search query returning 0 results

I'm using a query which returns 0 results but was working some weeks ago.  I checked the code and nothing has changed since then.  I created a Search Center Site on another port and using the same terms I get many results there.  I checked my scopes and they are all right. Nothing changed there either. Could someone help me figure out what may be the problem in my query.  Or maybe it's my Scopes/Content Sources configuration. SELECT URL, FileName, Title, Description, Rank, Size, HitHighlightedSummary, Path FROM SCOPE() WHERE freetext(defaultproperties, ' +légumes')  AND ( "scope" = 'Scope - My Portal - All Site - fr'  )    ORDER BY Rank DESCDaniel Siconnelli There is neither good nor evil... only mogwais and gremlins

Writing values back to a database

Hi All, I'm trying to write values back to an access database from an open source mathematical programming language (called glpk) using ODBC. I succeeded in doing so in most variables except one. The problem is described below: The following code gets an error when writing the data: \begin code:   table x3_iii {j in TF, k in C, p in P, t in T: x3[j,k,p,t]>0} OUT 'ODBC'   'FileDSN=.\d2.dsn'   'UPDATE ((Channels a INNER JOIN ChannelPeriodProducts b' 'ON a.ChannelID = b.ChannelID)' 'INNER JOIN TransformerTypes d' 'on a.OriginFacilityID = d.FacilityID' 'SET b.Quantity = ?'   'WHERE d.TransformerTypeID = ?'   'AND a.OriginFacilityID =?'   '    AND b.ProductID = ?'   '    AND b.PeriodID = ?':   x3[j, k, p, t], j, k, p, t; \end code Note that the sql is on multiple lines, because of a maximum strings limit in the glpk (but the way I used in the code is fine and worked without problems for writing other variables). Now, let me describe what I am basically trying to do: I'm trying to write the values for the variable x3[j,k,p,t] in its field "Quantity" in the table 'ChannelPeriodProducts'. The indices for that variable are j,k,p,t. The 'ChannelPeriodProducts' table has a "ChannelID", "PeriodID", "ProductID" and "Quantity" field

on submission the form doesn't write to the database

I have my code behind from my webform and it does everything but write to the database. The form comes up I can fill it out then click the button and it takes me to the thankyou.aspx page but no entry in the database. I can't find what I am doing wrong.using System;using System.Data;using System.Data.SqlClient;namespace orderfinal{    public partial class _Default : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        protected void btnSave_OnClick(object Src, EventArgs E)        {            if (Page.IsValid)            {                // Define data objects                SqlCommand comm;                // Open the connection                SqlConnection conn = new SqlConnection();     &n

using a database field as a hyperlink query?

I have three tables in my sql database contactssurvey answersrespondent_initialContacts holds all customer data with custid. survey answers has assigned everyone how took the survey a number in a field called respondent_no.respondent_initial holds input from a webform where I populated it with the custid from contacts and respondent_no from survey answers before the webform input is inserted. I want to send an email to them that had there respondent_no in a hyperlink to the webform so that when they entered their data into the webform it would use the repondent_no to determine where to insert the form data.Example joe clicks http://www.myplace.com/order.aspx?23             Mike clicks http://www.myplace.com/order.aspx?125it would look up respondent_no (23) from the respondent_initial table and insert the data in that row in the database for joe's webform entry and it would look up respondent_no (125) from the respondent_initial table and insert the data in that row in the database for mike's webform entry.my code behind looks like this// Create command                comm = new SqlCommand("INSERT INTO respondent_inital (Practice_Name, Address1, Address2, City, State, Zipcode, Phone, Email, Contact, Dealer, item_9223, item_9129, item

Query help to write case statement in Where clause?

Hi All, I have table something like this:- SELECT UserName, IsManager FROM Employee IsManager has only two values either 1 (which means user is a Manager) or 0 (which means user is not a Manager) Now I want to write below query:- DECLARE @IsManager INT SET @IsManager = 2 SELECT UserName, IsManager FROM Employee WHERE IsManager = CASE WHEN @IsManager = 1 THEN 1 WHEN @IsManager = 0 THEN 0 WHEN @IsManager = 2 THEN 1 | 0 ----- THIS IS NOT WORKING, when I set @IsManager value to 2 then where clause should be like this "IsManager = 1 OR IsManager = 0" END Can anybody help me out in modifying about query so that it produces both the results when @IsManager variable value "2". Thanks Regards, Kumar

how can I detect query results

Im trying to get the number of result in a select query in a database...how can I get the number(row) of result from a ExecuteReader() function?

Problems with SSRS 2008 Install when configuring a back-end database on a SQL Server 2008 R2 environ

We are tyring to configure SQL Server Reporting Services (SSRS 2008) not the R2 version with a SQL Server 2008 R2 version of database. We are facing error when the configuration manager within SSRS tries to execute its scripts against the database. Do you think that SSRS 2008 may have trouble using a SQL Server 2008 R2 version as the back-end? Also, what kind of permissions does the ID installing SSRS needs to have on the SQL Server database ?  Not much is available in the documenation or online.

My Site and Search Results Link back to Homesite

Hi, Just abouit finished my Sharepioint2010 portal and now cleaning up a few odds 'n' ends. If I click on My Site or People Search the resulting pages don;t allow you to 'Browse' back to the top level page of the Sharepoint site (ie. the Intranet Homepage). Although all my sub-sites have a 'Home' button aswell as the default S/Point home button on the top menu bar, MySite doesn't and I can't seem to add it. Any ideas ? Seems crazy that people can go into the MySite, navigate around but then have to type the server web address back into the Address bar to return from whence theyu came ! Cheers Ian

Query Designer - Pane - Results grayed-out?

In Query Designer, right click, select pane -- the option for Results is unavailable (grayed-out)?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend