sql-server-2008-r2

Does sql server minds the way records where inserted?

点点圈 提交于 2019-12-13 16:28:20
问题 (a "How it works" - question) Suppose I have this table : Id val ------------------ 1 a <-- 1 a 1 a 2 b <-- 2 b 2 b Now lets say I want the marked rows : Can I count on this query : select id,val from ( select id , val , row_number() over (partition by id order by id) as rn ) k where rn=1 to give me the Selected rows ? (notice the order by clause). will it consider the order as the order they were inserted ? 回答1: The behaviour is not guaranteed. Your query will return two rows, but which ones

Is it possible to column partitioning in SQL Server

自作多情 提交于 2019-12-13 16:17:38
问题 The size of each record of table is a performance parameter. that means if size of record was small SQL Server fetch more records in each read from physical hard. In most of our queries we not use all column of table, and may be some column use only in specific query. Is it possible for we partitioning columns of each table to have better performance. I use SQL Server 2008 R2. Thank you. 回答1: True column level partitioning comes with column oriented storage, see Inside the SQL Server 2012

Is it possible to change the datatype Date in Sql Server

那年仲夏 提交于 2019-12-13 16:01:09
问题 I live in Iran and we here in Iran use Solar dates instead of the Gregorian dates. Is it possible to change Date datatype from Gregorian date to Solar date. Also, I want to use the date function such as DateAdd() , DateDiff() , .. in my query. EDIT : Months desciption in solar date: 1- 31 day 2- 31 day 3- 31 day 4- 31 day 5- 31 day 6- 31 day 7- 30 day 8- 30 day 9- 30 day 10- 30 day 11- 30 day 12- 29 day (in Leap year 30 day) SUM-365 day in each year and start of solar date is 23-3-... of each

Identity column Vs Primary Key [closed]

被刻印的时光 ゝ 提交于 2019-12-13 14:06:31
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . How can we decide on to go with Identity column or Primary Key? 回答1: The two concepts are not mutually exclusive. All combinations are possible: An identity column that is also a primary key, An identity column

SQL Server Performance With Large Query

南笙酒味 提交于 2019-12-13 13:19:46
问题 Hi everyone I have a couple of queries for some reports in which each query is pulling Data from 35+ tables. Each Table has almost 100K records. All the Queries are Union ALL for Example ;With CTE AS ( Select col1, col2, col3 FROM Table1 WHERE Some_Condition UNION ALL Select col1, col2, col3 FROM Table2 WHERE Some_Condition UNION ALL Select col1, col2, col3 FROM Table3 WHERE Some_Condition UNION ALL Select col1, col2, col3 FROM Table4 WHERE Some_Condition . . . And so on ) SELECT col1, col2,

SQL Sum MTD & YTD

别来无恙 提交于 2019-12-13 13:17:09
问题 I have only just started looking into SQL. I have a SQL Server 2008 r2 database that will return two fields DocDate & InvValue. I need to sum the InvValues as MTD & YTD as of Today's Date So it looks like **Period** /////// **Total value** MTD ////////////111111.11 YTD /////////////999999.99 I have done a fair amount of Googling and can do one or the other with SUM & DATEPART, but I am stuck with trying to do both. Can someone give me some pseudo-code that would help me google a little

Pass A User-Defined Table to a Stored Procedure

给你一囗甜甜゛ 提交于 2019-12-13 12:02:01
问题 I have a User Defined Table that I am passing into a stored procedure from within a stored procedure. DECLARE @tmpInput MyTableType; --Table is populated from an INPUT XML exec ValidateInputXML SELECT * FROM @tmpInput TI WHERE TI.EntryType = 'Attribute'; Now this isn't giving me an error, but when I run a select from with the ValidateInputXML the table has no data. 回答1: You can also use Table-Valued parameter for your stored procedure. E.g. /* Create a table type. */ CREATE TYPE MyTableType

Can I use an Expression to set a variable in a “SQL Statement Task”?

女生的网名这么多〃 提交于 2019-12-13 10:59:37
问题 Can I use an Expression to set a variable in a "SQL Statement Task" ? I am designed an ETL solution loading a plain text file from a website. The user write the main parameters, like month, year, registercount, and press the processing button. The ETL solution starts. Until now, I am used to read/set variables with SQL statements inside same "SQL Statement Task" but sometimes they do not work properly when the solution is started from the web app with these same params used to set these

Insert string's each values into a single column

余生长醉 提交于 2019-12-13 10:22:29
问题 Here I want to insert the complete string each values into a column. For which I have written the following script: Example : Table : test create table test ( cola varchar(10), colb varchar(max), colc varchar(10) ); Note : Now I want to insert records like the following by calling stored procedure: cola colb colc ------------------ X1 M1 Z1 X1 M2 Z1 X1 M3 Z1 X1 M4 Z1 Stored Procedure : sptest CREATE PROC sptest @cola varchar(10), @colb varchar(max), @colc varchar(10) AS Declare @dynamic

How to Pass List<> to stored procedure

允我心安 提交于 2019-12-13 10:14:07
问题 I am trying to pass a list to database (SQL Server 2008 R2) using user defined table types but get some errors my code is: public int DAL_SaveIncramentSalary(tbl_Employee_Master obj, List < dtIncrementSalary > tbl) { try { SqlParameter[] objSqlParameter = new SqlParameter[4]; objSqlParameter[0] = new SqlParameter("@Company_ID", obj.Company_ID); objSqlParameter[1] = new SqlParameter("@Employee_ID", obj.Employee_ID); objSqlParameter[2] = new SqlParameter("@Salary_Month", obj.Govt_DA);