Hello all!This might be a newbie question, and there might be something Im just not thinking of right now, but I have a set of values that I need to get the average of but only from the middle 90%. Example:11 <-From here1234456 <- To here.7I thought I could solve it by subqueries and do the following:Select (((Select sum top 5 order asc) + (Select sum top 5 order desc)) - sum total)/rows*0.9 which would give me what I want, but I realised that when aggregating I cant order the subqueries.This is for an application (that will run the query on a sql-server) that only takes one query (although subqueries should be fine), and thats why I have a problem, I cant build any views or things like that.I guess my question is very simple: How can I get a sum of the bottom 5 percent without sorting descending?
I'm writing a page that will return data from my database to the user based on their search paramaters, over several pages with 20 matching records showing per page, and a next button on the bottom. Similar to the format of any search engine. However, I'd like to write this into the query, and I'm not sure how I would go about doing so. For example: "SELECT TOP 20 to 40 * FROM Northwind" Hopefully this makes sense. Is there any way of doing this? Thanks in advance,Russ
I am trying to concatenate three fields into one in a View. I have the following data: Last Name First Name Middle Initial (can be null)
I need my resultant field data to look like the following: "Doe, John P."
I'm having a problem writing SQL that is sensitive to placing the period after the middle initial only if there is a middle initial present. If there isn't a middle initial, I just want the following: "Doe, John".
I have tried the following CASE statement:
CASE WHEN middleInitial IS NOT NULL THEN ' ' + middleInitial + '.' ELSE '' END
However, I get an error indicating that the CASE statement is not supported in the Query Designer.
How can I resolve this problem in a View? Is there a function similar to ISNULL(middleInitial, '') that would allow for the "."?
Lets say I have a column of type varchar and need to extract an integer value from the middle of it. The string looks like this:'this part is always the same' + integer of varying length + 'this part is different but always the same length'Is there a way to trim the constant string lengths from the beginning and end?
So I have this query where i need to get the average date of about five different dates... Is there any way to do this or am I screwed. I looked at using the avg function but SQL server 2005 did not like that.
I need to display the middle initial from a name field that contains the last name, comma, and the middle name or initial.
Example data:
Jane,Smith Ron John,Dow L Mary Jane,Dow Welsh
The result I am looking for is to capture only the first letter of the middle name. In this data example, I would need to display the following on a separate column:
-- I have a first name field that sometimes contains only the first name, -- sometimes contains the first name and the middle initial, and -- sometimes contains the first name, a space, followed by NMI (for no middle initial) -- how do I correctly grab the first letter of the middle initial in all cases? -- I have been playing with patindex but its harder than I thought. guess I need a case -- statement in addition to this. Any idea how I can do this? -- thanks!
khosara writes "I have one parameter @String with value "My name is Khosara". How to get the value only "Is khos". Could you please help me, witch method shold i use. Thank in advance."
Hello The following command is for Name Split as First Name and Second Name. Please let me know based on the following only how to get Middle name. SELECT name, CASE WHEN CHARINDEX(',',Name) > 0 THEN SUBSTRING(Name,CHARINDEX(',',Name)+1,LEN(Name)-CHARINDEX(',',Name)) ELSE '' END AS Fname, CASE WHEN CHARINDEX(',',Name) > 0 THEN LEFT(Name,CHARINDEX(',',Name)-1) ELSE Name
Some of the databases that I inherited contain search that are based on finding a string anywhere within a last name such as:
WHERE lastName like '%smith%'
It is desired that each of these names be returned:
Smith Smithson Nesmith
What is presently done is that updates to the last name fields trigger that substrings of the last name be sent off into a substring table wtih retention of no 2-char substrings. For these three last names the following would be kept:
Well, how do you do it? I've not seen any report on this... so could it be next to impossible?
Say you have 10 records, 1-10 and you want to insert a new record between record 4 and record 5 in a SQL database, just how do you code it? And oh, each record uses the auto ID increment feature.
I have this assignment where i have a table full of two digit exam scores and I have to write a function that eliminate x number of top values and x number of bottom values and return all the middle values. When the function is called, obviously a number is entered such as 3 and the top 3 and bottom 3 scores are not returned. i.e. SELECT * FROM GetMiddleValues (3);
If anyone has any ideas on how to accomplish this, that would be great.
I have a table with 100,000 addresses and I need to change 'street' to 'st', 'avenue' to 'ave' and 'road' to 'rd'. These words can appear anywhere in the field. example
We have a problem importing the flat file data using SSIS into sql database.
For some erroneous files the package is just hanging with out any activity (Disk Reads/sec, Disk Writes/sec, Page faults/sec, Workingset Memory counters are const when the package hung). The package is giving the following messages before it is hung.
The column data for column "ServerName" overflowed the disk I/O buffer. An error occurred while processing file "M:Tani1APS-PRXY-02APS-PRXY-02-ISALOG_20060621_FWS_001-2006062106.Log" on data row 1. The PrimeOutput method on component "Firewall Data" (6109) returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. Thread "SourceThread0" has exited with error code 0xC0047038. Thread "WorkThread0" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. Thread "WorkThread0" has exited with error code 0xC0047039.
Even though it says has SourceThread0 has exited, it package is not terminating itself. We just want to ignore the errorneous file and move on to other files.
I tried altering DefaultBufferMaxRows in between 1000-10000, DefaultBufferSize to 1 MB €“ 20 MB which did not work out. Can one of you suggest us any resolution/work around for this issue? This is really a burning issue in our project would really appreciate any help!
I need help with a query, and I haven't seen anything like this in a SQL book.
I will use the Northwind database for this example. The tables I am using are Products, Order_Detail, and Orders. There is a many to many relationship between Products and Orders, that is resolved by the Order_Detail table. Suppose I want to find out which products are related to each order. How would I query the tables?
I need retrieve only strings that hold the sub-string in middle. no first no last just middle.
See: the sub-string is "test"
Yes: test test test Yes: take test test Yes: test test take Yes: take test take No: test test No: test take take No: take take test No: test
I prepare sample data...
declare @sample table(s varchar(50)); insert @sample values ('test test test'), ('test test'), ('test'), ('test take test'), ('test take take'), ('take test test'), ('take test take');
There doesn't seem to be consensus about when to put code in thedatabase or in the middle tier. There was a long discussion about thisin an Oracle newsgroup (message ID:ULcQb.466$KU5.37@nwrddc02.gnilink.net).Elsewhere there's been discussion about Microsoft SQL Server 2005adding the CLR to support stored procedures in languages such as C#. Ascan of the Web and discussion forums finds differing opinions aboutthis.Two authors have written articles that fall on different sides of thedebate."Keys to the Database"http://www.intelligententerprise.co...icleID=50500830"SOA, Multi-Tier Architectures and Logic in the Database"http://www.sqlsummit.com/Articles/L...TheDatabase.HTMJoe Celko wrote the first article, but his objections point toMicrosoft SQL Server 2005:"I have an article at WWSUG.com on how much I hate the CLR stuff thatMicrosoft is putting out."http://blog.intelligententerprise.c...ves/002419.html"The bad news is that SQL Server 2005 will you define your ownaggregatefunctions in a CLR language."Message id: Join Bytes!IBM DB2 and Oracle are doing the same thing with the .NET CLR. Is thisa non-issue or are all three companies misguided?
I'm working with SQL Server 2005, and I'm trying to sort the results based on a user selected letter. Say the user selects 'D' to filter his results. I'd like to return the results starting from D followed by E, F, G...Z, A, B, C. What I'm getting is the results for the D entries at the top of the result set, followed by A, B, C, E...Z.
A solution comes to mind that would be very long and db intensive, by querying on 'like 'D', followed by like 'E', followed by like 'F', etc, but I'm sure that there is a much more efficient way to do this. Below is the code that I'm using now.
' where @SortString = 'd' and @Test is a temp Table
BEGIN
Insert into @Test
Select CompanyName,ContactId, CompanyId
from vContacts where CompanyName like @SortString +'%'
Order by CompanyName
Insert into @Test
Select CompanyName,ContactId, CompanyId
from vContacts where CompanyName not like @SortString +'%'
In SQL Server 2008 when I click the middle button I could scroll up and down(scroll wheel) by just flicking the mouse. We just upgraded to 2012 and I can't do that on my Lenovo ThinkPad. I am using an external wired usb mouse(Intelli Mouse) to scroll.
I have SQL server 2008 and 2012 installed on the same machine scrolling works in 2008 but not in 2012.
I have to use a field that is calculated in a data flow process and call a database function (return a value) to do anther calculation; then return a value back to the data flow. I tried OLD DB Command but I cannot configure to return a value back to the same data flow. If there any transformations that can call a DB function and get a value from the function in the middle of the data flow process? Need more detailed instruction.
I am trying to write a query in sql query analyzer that will extract a date that appears after the first comma in the string. An example of the data is below:
Hi All, Im trying to migrate a N tiered solution written in Java and Berkeley DB(in memory DB product) to MS stack. ie the in memory DB is being used as a middle tier caching solution.
Im considering using SQLCE where Berkely DB was being used, im guessing that SQLCE being an inproc DB may be faster than using SQLExpress etc.
Has any one tried to do this before? and if so can you share your experience? Alternatively if you can provide any resources on the web that discuss SQLCE performance(ie not when run on WinCE etc)/ comparison of query performance between SQLCE and SQL Express/Standard that would be great.
DECLARE @DTstart SMALLDATETIME, @DTend SMALLDATETIME SELECT @DTstart = "980801", @DTend = "980810" SELECT ' processing from ', @DTstart , ' to' , @DTend SELECT GETDATE(), 'start LOOP' DO WHILE @DTstart <= @DTend BEGIN exec p_pmp_charg_unif_csg @DTstart WAITFOR DELAY "00:01:00" SELECT @DTstart = DATEADD(DAY,1,@DTstart ) END SELECT GETDATE(), 'start LOOP'
I´m having the following problem with SQL 7. When running the loop, all in a sudden it stops - there´s no error message on result. But checking out the current error log, I´ve found the error 17824 reported .
According to the BOL, this error is related to 'priority boost' and troubles in connection between server and client.
This SQL server 7 has the following configuration:
- 128Mb of RAM, and SQL7 can use from 0 to 128MB - boost SQL Server priority on Windows NT - maximum concurrent user connection is 0
Is there someone that had similar problem in SQL 7?
I usually do this through Access so I'm not too familiar with the string functions in SQL. My question is, how do you remove characters from the middle of a string?
Ex: String value is 10 characters long. The string value is X000001250. The end result should look like, X1250.
I've tried mixing/matching multiple string functions with no success. The only solution I have come up with removes ALL of the zeros, including the tailing zero. The goal is to only remove the consecutive zeroes in the middle of the string.
I have to figure out the items that Legal Name implies individual but Legal Entity Structure indicates a incorporation type. In this sample, you can see Alexander, Justin N. is my target. But my problem is how should I use a query to figure out which one is a individual's name? How should I write a function to check the name format (Last, First Middle)?
Legal Name ////////////////////////////////////// Legal_Entity_Struct
S & H Farm Supply, Ltd.////////////////////////////Company F.M.Abbott Power Equipment,Co.///////////////Company Ray's Dixie Chopper, Inc.////////////////////////// Company Alexander, Justin N. ///////////////////////////////// Company Alameda Power Equipment, Inc.//////////////// Company
i have a column name remarks and i want to retrieve data like by deleting some of the leading charaters and some last characters and show the middle one.
like remarks has CALLTRANSFER_OVER_SIP:XfrTime=86.05599975585938_en and i want to show only "XfrTime=86.05599975585938" this much