sql-server-2008-r2

How to get the name of a the student who got max marks in each subject?

可紊 提交于 2019-12-06 15:04:30
I have the following table Name | Subject | Marks -------------------------- a M 20 b M 25 c M 30 d C 44 e C 45 f C 46 g H 20 Here I have a "Student" table I want to get the Name of the student who got Max marks from each subject from the student table like the following OUTPUT. Name | Subject | Marks c M 30 f c 46 g h 20 You can use the ROW_NUMBER function to return only the "best" row per subject: SQL Fiddle MS SQL Server 2008 Schema Setup : CREATE TABLE Student ([Name] varchar(1), [Subject] varchar(1), [Marks] int) ; INSERT INTO Student ([Name], [Subject], [Marks]) VALUES ('a', 'M', 20), (

Convert comma delimited string to table or array in sql server 2008 without using dbo.split

偶尔善良 提交于 2019-12-06 14:13:56
How to convert comma delimited string to table or array in sql server 2008 without using dbo.split function because the system doesn’t support this function? Eg of string: ’12,14,15’ Change this to *Table column* 12 14 15 Or array=[12,14,15] I would like to insert comma separated string values into a table ultimately. Thanks dbo.split is probably user defined function, so you need to define it. Otherwise you can use XML + CROSS APPLY : Demo DECLARE @string NVARCHAR(100) = '12,14,15' ;WITH cte AS ( SELECT CAST('<XMLRoot><RowData>' + REPLACE(t.val,',','</RowData><RowData>') + '</RowData><

EntityFramework : Calling ToList() on IQueryable with ~11.000 records takes 10 seconds

我与影子孤独终老i 提交于 2019-12-06 13:46:11
I want to return a relatively large number of records from SQL Express 2008 R2 server, via EntityFramework 4 through WCF service to a WCF client. My test table contains around 11.000 records at the moment. The LINQ query is as simple as this: Database DB = new Database(); // create object context var retValue = DB.Entities.Persons .Include("District") .Include("District.City") .Include("District.City.State") .Include("Nationality") return retValue.ToList(); This takes about 10 seconds to complete. The same SELECT query takes less than 1 second when executed in SQL Server Managament Studio.

TCP Provider: The semaphore timeout period has expired

让人想犯罪 __ 提交于 2019-12-06 13:12:54
In Sql Server2008 R2 and Windows Server 2008R2, when I start Replication I have this error: TCP Provider: The semaphore timeout period has expired Please help me to solve it. in order to fix the error: System.IO.IOException: The semaphore timeout period has expired. ​Solution​ I have done below NIC changes to resolve this error. Open the Network and Sharing Center. Right click on Ethernet Adapter>>Properties Select Client for Microsoft Networks Click on Configure Tab Click on Advanced Tab And then - Disable the below settings IPv4 Checksum offload Large Send Offload V1(Ipv4) Large Send Offload

How do I get MS LightSwitch to recognize my View?

亡梦爱人 提交于 2019-12-06 12:13:33
I've created a View from a table in another database. I have dbo rights to the databases so viewing and updating is not a problem. This particular View did not have an "id" column. So I added one to the View by using ROW_NUMBER. Now I had a problem with a table, in the same database, not showing up in LightSwitch but that was solved by changing the id column to be NOT NULL. I haven't done any real manipulation in LightSwitch. I'm still in the Import Your Data Source stage (ie. very beginning). This View, in LightSwitch, is going to be read-only. No updating or deleting. From what I've read,

What is the best way to loop over a table's rows?

戏子无情 提交于 2019-12-06 11:48:42
What is the best way to loop over a database table's rows in SQL Server 2008 R2? I am looking for something which is fairly similar to writing foreach ( ) and quite performant. Thanks BradC Best performing: don't loop over a table's rows. Use set-based operations. Here's a good discussion of WHY Perhaps you want a CURSOR? See SQL Server Cursor Examples (also provides links and discusses issues/alternatives/reasons). It may or may not meet the definition of 'best' -- SQL DQL really does like to work with 'set operations' (and this is what it's designed to do, there are some caveats with using

SAS SQL Pass Through

为君一笑 提交于 2019-12-06 11:44:37
问题 I would like to know what gets executed first in the SAS SQL pass thru in this code: Connect To OLEDB As MYDB ( %DBConnect( Catalog = MYDB ) ) ; Create table MYDB_extract as select put(Parent,$ABC.) as PARENT, put(PFX,z2.) as PFX,* From Connection To MYDB ( SELECT Appointment,Parents,Children,Cats,Dogs FROM MYDB.dbo.FlatRecord WHERE Appointment between '20150801' and '20150831' And Children > 2); Disconnect from MYDB; Since MS SQL-Server doesn't support the PUT function will this query cause

How To Separate Data Into Two Columns [duplicate]

我的未来我决定 提交于 2019-12-06 11:24:48
问题 This question already has answers here : Attendance IN and OUT (3 answers) Closed 12 months ago . Consider the following table structure and sample data - EmpID InputDateTime StatusINOUT ------------------------------------- 1 2018-05-26 08:44 1 1 2018-05-26 08:44 2 2 2018-05-28 08:44 1 2 2018-05-28 12:44 2 1 2018-05-21 08:44 1 1 2018-05-21 10:44 2 2 2018-05-23 08:44 1 2 2018-05-23 08:44 2 Now I want to separate column InputDateTime into two columns i.e., INTIME(1) and OUTTIME(2) . The logic

Counting sequential events and counts of sequences SQL

流过昼夜 提交于 2019-12-06 10:50:59
问题 I have a query that I built using an answer found here and it was very helpful. I have added some things to it to suit my needs. One of the things that I added was a ROW_NUMBER() in order to count how many times someone has been readmitted within 30 days over any time length. I have inserted the cte results into a temp table as suggested in the first answer and by a question that was posted here. This does not solve thought, the sequence length and sequence count issue. This is the query: --

How to take substring from field between specific chars

删除回忆录丶 提交于 2019-12-06 10:10:42
问题 I have field which contain a value like: F28_TIT245_0_90A_OOC_LCL by AARBITMA(aarbitma@LC13UPE-CIM) I want to take the name between '(' and '@' which is "aarbitma" . How can I do it? I'm running on SQL Server 2008R2 回答1: -- there are no checks for wrong input text -- this is TODO to be done yourself DECLARE @text VARCHAR(100) DECLARE @start INT DECLARE @end INT SET @text = 'F28_TIT245_0_90A_OOC_LCL by AARBITMA(aarbitma@LC13UPE-CIM)' SELECT @start = PATINDEX('%(%@%', @text) SELECT @end =