I am running this stored Prcedure and getting multiple lines for the output. Below are the queries the create the temp table (its holding the data), and the query that generates the output:
/* this creates the temp table */
Select count(*) as 'Donations', d_vst_id
into Donations_temp
from dnr_vst_db_rec
where convert(varchar(10),d_vst_date) between convert(varchar(10), @Beg_Vst_Date, 112) and convert(varchar(10), @End_Vst_Date, 112)
and d_vst_status = 'DN'
and d_vst_dontyp in ('E1', 'E2')
group by d_vst_id
/* this query generates the output */
select distinct cast(getdate() as varchar(30)) as 'TODAY'
,CONVERT(varchar(10), @Beg_Vst_Date,101) as 'BEGDTE'
,CONVERT(varchar(10), @End_Vst_Date,101) as 'ENDDTE'
,case Donations
when '1' then sum(1)
else 0
end as 'ONE1'
,case Donations
when '2' then sum(1)
else 0
end as 'ONE2'
,case Donations
when '3' then sum(1)
else 0
end as 'ONE3'
,case Donations
when '4' then sum(1)
else 0
end as 'ONE4'
,case Donations
when '5' then sum(1)
else 0
end as 'ONE5'
,case Donations
when '6' then sum(1)
else 0
end as 'ONE6'
,case Donations
when '7' then sum(1)
else 0
end as 'ONE7'
,case Donations
when '1' then Sum(0)
when '2' then Sum(0)
when '3' then Sum(0)
when '4' then Sum(0)
when '5' then Sum(0)
when '6' then Sum(0)
when '7' then Sum(0)
else Sum(1)
end as 'ONEA'
from Donations_temp
group by Donations
Hi All, I'm saving the output of a query into an html file. The dashed lines above rows that have a select in it are showing up in the final doc and are playing havoc with my page. Does anyone know of a command to stop them from appearing. nocount just suppresses the rows affected message. ANY help is appreciated.
I am trying to use a command line program to run a stored procedurethat generates output in a comma-delimitted format. Somehow, ISQL orOSQL always wrap the lines at 256 characters. I believe this hassomething to do with the column width switch (-w). But enlarging thecolumn width to 800 characters max still doesn't help. The followingis a stored procedure that is essentially doing what my storedprocedure is doing:create procedure MyTest asset ansi_padding onset nocount ondeclare @sTest varchar(300)-- Output three lines. Each line has 259 characters.select @sTest = "1234 6789 ... 1234 6789"print @sTestselect @sTest = "1 3 5 7 9 ... 1 3 5 7 9"print @sTestselect @sTest = "1 3 5 7 9 ... 1 3 5 7 9"print @sTestset nocount offreturn( 0 )I invoke this stored procedure using this command:isql -SMyDbSrv -E -dMyDb -w800 -x800 -h-1 -n -Q"exec MyTest"-oMyTest.txt-- or --osql -SMyDbSrv -E -dMyDb -w800 -h-1 -n -Q"exec MyTest" -oMyTest.txtBut they have the same problem. The output lines all wrap around at256 characters.Strangely, if I store the result in a temporary table, and then useSELECT to output the result from the temporary table, I will not havethat problem. Seem like the "-w" switch only works for output fromtables, but not for output coming from PRINT. Unfortunately, usingthis approach has another set of problems (one blank space in front ofeach line, "number-of-rows affected" shows up at the bottom).Therefore, I would like to stick with using PRINT statements to outputthe result.Please suggest a way to fix this line-wrapping-around problem.Thanks.Jay Chan
I am generating hundreds of lines of sql with a tool and wish to execute is in runtime. The sql consists of table creation, procedure creation, aswell as inserts and updates. When i try with SqlDataAdapter I get an error. Does anyone have a solution on what I can do?
I know very simple SQL queries but I need help with this one. I have multiple lines in a SQL database that I need to run. Basically, I need to run this (the bracketed text and the XXX are place holders):
DELETE FROM [tableName] WHERE [columnName] = 'XXXXX'
But I need to run it around 90 times where XXXXX is a unique variable each time. I could create 90 lines similar to this one but that would take way too much time to run. Any suggestions for a noob?
Thanks,
- MT
-=<>=-=<>=-=<>=-=<>=-=<>=- Matt Torbin President Center City Philadelphia Macintosh Users Group http://www.ccpmug.org/
Hi, I have a scenario, where I have a string column from database with value as "FTW*Christopher,Lawson|FTW*Bradley,James". In my report, I need to split this column at each " | " symbol and place each substring one below the other in one row of a report as shown below .
How can I run through an array of ID's and delete the fields associated to it in a single table? I have a lot of bad data that needs to be removed. BTW, I'm using the SQL Server Management Studio to do this.
I'm currently doing by hand by using the following.
USE database; DECLARE @id integer SET @id = XXXXX DELETE FROM table WHERE id = @id;
I would like to use the same code but with a slight variation to support an array.
i have the following stored procedure which does a hit to a server and returns the response
it is hitting the server but the problem is the response is null
any ideas what i'm doing wrong
/****** Object: Stored Procedure dbo.http_geturl Script Date: 2/12/2007 2:00:40 PM ******/ ALTER procedure [dbo].[http_geturl]( @sUrl varchar(8000), @response varchar(8000) out) As Declare @obj int ,@hr int ,@status int ,@msg varchar(255)
exec @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT if @hr < 0 begin /* Raiserror('sp_OACreate MSXML2.ServerXMLHttp failed', 16, 1) */ return end
exec @hr = sp_OAMethod @obj, 'Open', NULL, 'GET', @sUrl, false if @hr <0 begin set @msg = 'sp_OAMethod Open failed' goto eh end
exec @hr = sp_OAMethod @obj, 'send' if @hr <0 begin set @msg = 'sp_OAMethod Send failed' goto eh end
exec @hr = sp_OAGetProperty @obj, 'status', @status OUT if @hr <0 begin set @msg = 'sp_OAMethod read status failed' goto eh end if @status <> 200 begin set @msg = 'sp_OAMethod http status ' + str(@status) goto eh end
exec @hr = sp_OAGetProperty @obj, 'responseText', @response OUT if @hr <0 begin set @msg = 'sp_OAMethod read response failed' goto eh end exec @hr = sp_OADestroy @obj return
I need to, ultimately, create a flatfile for exporting insurance information to a third-party vendor. Each individual is to have no more than 1 line per file, which contains their coverage information, if any, on 4 different type of insurance. What i need is for 2 fields in a table to determine the output for multiple fields in the flatfile.
What I have so far works, to an extent. If I have insurance types 1, 2, 4 (of types 1-4) required output is (__ = 2 blank spaces):
1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E
Y N __ MD XX Y N __ MD XX N __ __ __ __ Y N __ DN XX
If they have coverage, A always = Y, B always = N, C always = blank(null), D is their ins. type, E is their cov. type(CASE statement). if they DON'T have that type of coverage, A always = N and the remaining field are NULL.
After a lot of work, and scouring a forum or 2, I attempted a whole lot of CASE functions. Below is an sample of code representing the 1x statements. This same code is repeated 4 times with the 1x being altered with 2x, 3x, 4x.
CASE HB.PLAN_TYPE
WHEN '10' THEN 'Y'
ELSE 'N' END AS 1A,
CASE HB.PLAN_TYPE
WHEN '10' THEN 'N'
ELSE ' ' END AS 1B,
' ' AS 1C,
CASE HB.PLAN_TYPE
WHEN '10' THEN HB.BENEFIT_PLAN
ELSE ' ' END AS 1D,
CASE HB.PLAN_TYPE
WHEN '10' THEN (CASE WHEN HB.COVRG_CD ='1' THEN 'XX'
WHEN HB.COVRG_CD ='2' THEN 'YY'
WHEN HB.COVRG_CD ='3' THEN 'ZZ'
ELSE 'WW' END)
ELSE ' ' END AS 1E,
It works to an extent. While the desires/required output it above, the output this produces (same scenario) is:
1A 1B 1C 1D 1E 2A 2B 2C 2D 2E 3A 3B 3C 3D 3E 4A 4B 4C 4D 4E
N __ __ __ __ N __ __ __ __ N __ __ __ __ Y N __ DN XX
While there is supposed to be 1 line, regardless of number of insurance types, it only produces 1 line per type. I first tried this in Access, and was able to get it to work, but it required multiple queries resulting in a crosstab, export to Excel and manually manipulate the data, export to text file to manipulate, import back into Excel to manipulate, import back into Access and finally export into a flatfile. Far too much work to produce a file which is why I'm trying to convert it to raw SQL. Any assistance in this matter would be greatly appreciated.
I am working on conversion of Crystal reports to SSRS. The existing report has two level of grouping. So I have included 2 list inside a third list and then done the grouping. Is there another way to do multiple grouping ? Every thing is working fine except for getting one extra blank page at the end of report with only header and footer. I have properly checked the body height and width and page margins. It has something to do with list but i cant figure out what.
I am in doubt if its possible to make a select statement which enables me to consolidate multiple lines in the same table.
I have a table with a lot of companies and figures for each company.
Some of the companies owns some of the other companies in the table and in reverse, some of the companies are owned by some of the companies in the table.
I have a lot of columns, but basically the most important columns are:
Company Name, Company Mother , Company Daughter.
Each company has also a revenue column.
What I want to do is to consolidate all figures for absolute mothers e.i. companies which are not owned by another company in the list.
I therefore need a select statement which says something like:
Get the revenue of companies not owned by another company (e.i. absolute mother). Add to this, the revenue of all its daughters. Add to this the revenue of all the daughters daughters etc. until there are no daughters left.
In other words - aggregate the revenue for all the companies in the group under the name of the ultimate parent company.
I can easily select and add the revenue for the first level of direct daughters, but I dont know how many more daughters the daughters has etc.
SELECT ID1, ID2, type, (case when type = '1' then sum(value) else '0' end) as Value1, (case when type = '3' then sum(value) else '0' end) as Value2, (case when type <> '1' and type <> '3' then sum(value) else '0' end) as Value3 FROM table1 WHERE ID1 = 'x' and ID2= 'y' GROUP BY ID1, ID2, Type
We are using a table that may give 1 to and unknown number of data elements (ie. years) . How can we break this to show only three years in each row. Since we don't know the number years we really won't know the number of rows needed. Years are stored in their own table by line.
car make year1 year2 year3 A volare 1995 1996 1997 a volare 1997 1998 1999 b toyat 1965 1966 1968
We can pivot out the first X# but we don't know how many lines so we don't know how many rows we will be creating.
I am having probelms trying to get a stored proedure to return an output value. The outline of the specific request is that I supply a varchar which is unique within a set of tables (tables named in another table). I want to search each of the tables until I find the one that has the value and when found return the GUID of the row and the table name. I have not been successful in getting the value of the GUID (an int) to be returned. If I run in debug and stop after the SQL call I can see the value in the SQL output parameter but it does not appear in the variable I specified in the SQL parameter setting. I am probably doing something simplly wrong but cannot see it. Please help if you can. Regards, Major (that is my Christian name ;-) The code files are copied below. Web app code sing System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using EFormsLIB; public partial class _Default : System.Web.UI.Page { String gstrConnectionString; // Connection to the SQL database, set in the config file to allow for changes while testing and running protected void Page_Load(object sender, EventArgs e) { // Read the connection string from the config file EFormsRoutines r = new EFormsRoutines(); gstrConnectionString = r.ReadConfigString("EForms21ConnectionString", ""); } protected void btnCancel_Click(object sender, EventArgs e) { this.Dispose(); } protected void btnGet_Click(object sender, EventArgs e) { // Get GUID for the form using UniqueDocID as the BlueWare ID. int intGUID = -1; SqlConnection SqlCDB = new SqlConnection(gstrConnectionString); SqlCommand SqlCmd = SqlCDB.CreateCommand(); SqlCmd.CommandText = "GetGUIDfromBWID"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter BWIDParameter = new SqlParameter(); BWIDParameter.ParameterName = "@BWID"; BWIDParameter.SqlDbType = SqlDbType.VarChar; BWIDParameter.Size = 30; BWIDParameter.Direction = ParameterDirection.Input; BWIDParameter.Value = TextBox1.Text; SqlCmd.Parameters.Add(BWIDParameter); SqlParameter GUIDParameter = new SqlParameter(); GUIDParameter.ParameterName = "@GUID"; GUIDParameter.SqlDbType = SqlDbType.Int; GUIDParameter.Direction = ParameterDirection.Output; GUIDParameter.Value = intGUID; SqlCmd.Parameters.Add(GUIDParameter); SqlCmd.Connection.Open(); int ret1 = SqlCmd.ExecuteNonQuery(); SqlCmd.Connection.Close(); Label1.Text = intGUID.ToString(); } } web app aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 48px; position: absolute; top: 24px" Text="Label"></asp:Label> <asp:Button ID="btnGet" runat="server" OnClick="btnGet_Click" Text="Get" style="z-index: 101; left: 8px; position: absolute; top: 48px" /> <asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click" Text="Cancel" style="z-index: 102; left: 64px; position: absolute; top: 48px" /> <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 103; left: 48px; position: absolute; top: 0px" Width="48px"></asp:TextBox> <asp:Label ID="Label2" runat="server" Style="z-index: 104; left: 0px; position: absolute; top: 0px" Text="BWID"></asp:Label> <asp:Label ID="Label3" runat="server" Style="z-index: 106; left: 0px; position: absolute; top: 24px" Text="GUID"></asp:Label> </div> </form> </body> </html> SQL procedure set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[GetGUIDfromBWID] @BWID varchar(30), @GUID int outputASBEGIN SET NOCOUNT ON; declare formscursor cursor for select formname from forms for read only declare @found int, @formname varchar(30) select @found = 0 open formscursor fetch next from formscursor into @formname while (@found = 0) begin if (@@fetch_status <> 0) select @found = 2 else begin if @formname = 'UAT040' begin if (select count(*) from UAT040 where BWID = @BWID) =1 begin select @GUID = (select GUID from UAT040 where BWID = @BWID) select @found = 1 end end else if @formname = 'GEN001' begin if (select count(*) from GEN001 where BWID = @BWID) =1 begin select @GUID = (select GUID from GEN001 where BWID = @BWID) select @found = 1 end end else if @formname = 'GEN002' begin if (select count(*) from GEN002 where BWID = @BWID) =1 begin select @GUID = (select GUID from GEN002 where BWID = @BWID) select @found = 1 end end else if @formname = 'CFT001' begin if (select count(*) from CFT001 where BWID = @BWID) =1 begin select @GUID = (select GUID from CFT001 where BWID = @BWID) select @found = 1 end end fetch next from formscursor into @formname end end deallocate formscursor if @found = 2 select @GUID = -16 select @GUIDend
Hi, I have this output, @RegisterFlag int OUTPUTand I have a transaction going on, so my code (I just put some relevant code here) is: 1 BEGIN TRAN 2 SELECT @getDealername = OrgName FROM Org WHERE OrgName = @DealerName 3 If @getDealername is null 4 5 ELSE 6 BEGIN 7 set @RegisterFlag = 2 8 ROLLBACK TRAN 9 RETURN 10 END 11 12 COMMIT TRAN 13 set @RegisterFlag = 1 The problem I am facing now is I couldn't get @RegisterFlag = 2 return back to my asp.net code when it reached line 7, instead I got this error mesg:Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0. How do I fix this? Many big thanks.
We have a service written in c# that is processing packages of xml that contain up to 100 elements of goods consignment data.
In amongst that element is an identifier for each consignment. This is nvarchar(22) in our table. I have not observed any IDs that are different in length in the XML element.
The service picks up these packages from MSMQ, extracts the data using XPATH and passes the ID into the SPROC in question. This searches for the ID in one of our tables and returns a bool to the service indicating whether it was found or not. If found then we add a new row to another table. If not found then it ignores and continues processing.
The service seems to be dealing with a top end of around 10 messages a minute... so a max of about 1000 calls to the SPROC per minute. Multi-threading has been used to process these packages but as I am assured, sprocs are threadsafe.It is completing the calls without issue but intermittently it will return FALSE. For these IDs I am observing that they exist on the table mostly (there are the odd exceptions where they are legitimately missing).e.g Yesterday I was watching the logs and on seeing a message saying that an ID had not been found I checked the database and could see that the ID had been entered a day earlier according to an Entered Timestamp.
USE [xxxxxxxxxx] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
[code]....
So on occasions (about 0.33% of the time) it is failing to get a bit 1 setting in @bFound after the SELECT TOP(1).
change @pIdentifier nvarchar(25) to nvarchar(22) Trim any potential blanks from either side of both parts of the identifier comparison Change the SELECT TOP(1) to an EXISTS
The only other thought is the two way parameter direction in the C# for the result OUTPUT. I have been unable to replicate this using a test app and our test databases. Have observed selects failing to find even though the data is there, like this before?
I have coded a stored procedure to return nearly all of the columns of a single record selected by using a unique key value. The record is in an SQL database, not within an in-memory DataSet. All of the parameters that I wish to have returned to my program are defined as OUTPUT; the two key values are defaulted to INPUT, as there is no need to return them to the calling program. I also have defined the direction of these parameters in the calling SQLDataAdapter function. However, when I run this, the values returned are either the current date for my DateTime parameters, Nothing for my Char parameters or 0's for my integer parameters.
When I try testing the sproc alone, by using the "Step Into Stored Procedure" action in Visual Studio, I get a message in the Debug Output window indicating that parameter @TktClassID was expected and not supplied. This is an OUTPUT parameter, which makes me question why I should be providing any sort of value for it within my VB code. Following are the function definition from my SQLDataAdapter class that calls my sproc, and the sproc itself. I appreciate any help that anyone can provide.
**FUNCTION DEFINITION FROM SQLDataAdapter Class
Public Function Fetch(ByVal ticket As Ticket) As Ticket Dim connbuilder As New System.Data.SqlClient.SqlConnectionStringBuilder connbuilder("Data Source") = "ITS-KCGV7VZSQLEXPRESS" connbuilder("Integrated Security") = "True" connbuilder("Initial Catalog") = "ITSHelpDesk" Using conn As New System.Data.SqlClient.SqlConnection(connbuilder.ConnectionString)
Using comm As New System.Data.SqlClient.SqlCommand("dbo.TicketFetch", conn) conn.Open() comm.CommandType = CommandType.StoredProcedure Dim parm As System.Data.SqlClient.SqlParameter
This is on a brandnew Win2003 server install with SQL Server 2005, RS 2005 and VS.NET 2005. I'm not able to log to the reportserver site to configure/publish reports. I'm logged in the system as administrator.
From IE6 I enter http://localhost/reportserver or http://localhost/reports and all I get is: Server Error in '/ReportServer' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0016: Could not write to output file 'c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files eportserver1bbf2d182968d42eApp_global.asax.konkdp27.dll' -- 'The directory name is invalid. '
Source Error:
[No relevant source lines] Source File: Line: 0
Show Detailed Compiler Output:
c:windowssystem32inetsrv> "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727csc.exe" /t:library /utf8output /R:"C:WINDOWSassemblyGAC_32System.Web2.0.0.0__b03f5f7f11d50a3aSystem.Web.dll" /R:"C:WINDOWSassemblyGAC_MSILSystem2.0.0.0__b77a5c561934e089System.dll" /R:"C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files eportserver1bbf2d182968d42eassemblydl37d9e24c3 0719bf6_b4d0c501ReportingServicesWebServer.DLL" /out:"C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files eportserver1bbf2d182968d42eApp_global.asax.konkdp27.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699 "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files eportserver1bbf2d182968d42eApp_global.asax.konkdp27.0.cs" "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files eportserver1bbf2d182968d42eApp_global.asax.konkdp27.1.cs"
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42 for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727 Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
error CS0016: Could not write to output file 'c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files eportserver1bbf2d182968d42eApp_global.asax.konkdp27.dll' -- 'The directory name is invalid. '
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
I've checked all permissions every where, I even allowed everyone full control to the entire C: drive, I uninstalled and reinstalled IIS6 (aspnet_regiis.exe) and nothing worked.
For this id: 0793319, my beginning date is 2011-09-06
108203492014-09-022015-06-30 208203492013-09-032014-09-01 308203492012-09-042013-09-02 408203492011-12-122012-07-03--not a continuous date range
For this id: 0793319, my beginning date is 2012-09-04
108203492014-09-022015-06-30
For this id: 0820349, my beginning date is 2014-09-02
To find continuous date, you look at the beginning date in row 1 and end date in row 2, then if no break in dates, row 2 beginning date to row 3 end date, if no break continue until last date There could multiple dates up to 12 which I have to check for "no break" in dates, if break, display beginning date of last continuous date.
I have an SQL statement to find attractions between certain longitude and latitude values. The attraction i have already added to the database to test has values 51.502899 and 0.003552 for latitude and longitude. As you can see these values fall within the limits of the statement below but nothing is returned.
SELECT * FROM Attractions WHERE (Lat BETWEEN 51.51998 AND 51.49999) AND (Long BETWEEN 0.014 AND -0.006);
I'm getting 3 copies of the result set expected, could someone take a look and tell me why. I know I covered this in school, but I can't remember the issue. Thanks
SELECT P.Quantity as Qty, P.ItemID, P.VendorCode, P.Descr as Description, P.UnitPrice as Price, P.Amount, I.Freight, Rcvd = 0, I.QtyRcvd as Ship FROM PurchaseOrderItems P, ReceivedItems I, Received R WHERE P.POID = R.POID AND R.IntRcdID = I.PRID AND P.POID = 193
I have two tables and I want to return data from both. Currently my select statement is returning just 1 child record for each parent record and I want to return all child records that match the parent record.
tblPerson - holds basic person data. tblPersonHistorical - holds a dated snapshot of the fkPersonId, fkInstitutionId, and fkDepartmentId tblWebUsers - holds login data specific to a web account, but not every person will have a web account
I want to allow my admins to search for users (persons) with web accounts. They need to be able to search by tblPerson.FirstName, tblPerson.LastName, tblInstitutions.Institution, and tblDepartments.Department. The only way a Person record is joined an Institution or Department record is through many -> many junction table tblPersonHistorical.
People place orders and make decisions in our system. Because people can change institutions and departments, we need an historical snapshot of where they worked at the time they placed an order or made a decision. Of course that means some folks will have multiple historical records. That all works fine.
So when an admin user wants to search for webusers, I only want to return data, if possible, from he most recent/current historical records. This is where I am getting bogged down. When I search for a specific webuser I simply do a TOP 1 and ORDER BY DateCreated DESC. That returns only the current historical record for that person/webuser.
But what if I want to return many different webusers, and only want the TOP 1 historical for each returned?
Straight TOP by itself won't do it. GROUP BY by itself won't do it.
I have a query running without issue on around 100,000 results however i have a couple where my MAX aggregate is returning two results for a MAX(date time) and i cannot figure out why. I have paired down the query to try and work it out but still don't know.
My query now looks like this (i have remove most columns)
SELECT STATUS, RunOn, sort, T_ID FROM dbo.Results WHERE (RunOn IN (SELECT MAX(RunOn) FROM dbo.Results group BY T_ID) AND T_ID = 21405)
ORDER BY sort
I added the T_ID = 21405 to restrict the results to the problematic results, if i set T_ID to any other test result i get one value based on the latest RunOn, but for some reason with this T_ID i get two values, the latest one and one slightly older... The date time looks ok, i just can't work out why the latest and one older result are returned !
The original query was grouping by more items but i removed those to try and work out what is going one, as mentioned for 99.9% of results it works perfectly, but for this one i don't know.
Required output pic_col_1, name_col_1, pic_col_2, name_col_2, pic_col_3, name_col_3 photo1.jpg, john smith, photo2.jpg, jane doe, photo3.jpg, bob brown photo4.jpg, mary brown, photo5.jpg, sue smith, photo6.jpg, bob rogers
Normally, I would just query the data and have the client data loop over the dataset to create the required output, however in this application it is not an option...
This is probably very elementary to someone more experienced, but I'm having a hard time coming up with a way to do the following:
SELECT * FROM Transactions WHERE MyField LIKE (SELECT MyValues FROM SearchValues)
But I can't because the subquery will return multiple rows. That's all I'm really trying to do - search all the rows in Transactions.MyField for any of the search values returned from the subquery.
And I can't restructure the SearchValues table to combine them into a single-row comma-delimited field or anything like that.
I've got this sql statement that keeps returning the wrong data. (it's related to a previous post, but is different)
Code: SELECT C.NAME, OL.PART_ID, SL.SHIPPED_QTY FROM CUSTOMER C INNER JOIN USERS U ON C.ID = U.ID INNER JOIN ORDERS O ON C.ID = O.ID INNER JOIN ORDER_LINE OL ON O.ID = OL.ORDER_ID
my stored procedure performs actions of deletion and insertion. Both the inserted and deleted items are output in temp tables with single column. Is there a way to return the content of these two tables? Is there a way to return a table from the stored procedure?