sql-server-2008-r2

Understand Unicode and code pages in SQL Server collations

风格不统一 提交于 2019-12-06 00:50:50
Why all SQL Server 2008 R2 collations are associated to a code page. Are all collations unicode ? How to choose a collation when our database is used by several languages using differents code pages ? Thank you. CHAR vs. NCHAR (ie. Non-Unicode vs. Unicode) defines the character storage encoding. Collations define... collation (ie. sort order and comparison rules). They are different concepts, although often confused. The confusion stems from the fact that the client tools use the collation of non-Unicode data as hint to choose the code page of the data. See Code Page Architecture . This means

SUBQUERY total performance vs case sum performance

情到浓时终转凉″ 提交于 2019-12-06 00:48:43
I have to do sum of some columns basis on where clause for better understanding i am implementing a temporary table here declare @tbl table(a int ,b int,c int) insert into @tbl values(1,2,3) insert into @tbl values(2,2,3) insert into @tbl values(1,3,1) insert into @tbl values(1,2,3) insert into @tbl values(1,2,3) and for finding sum of a,b,c ob basis of value of a,b,c ; i am using following query SELECT ( SELECT SUM(a) from @tbl where a=1 )AS a , (SELECT SUM(b) from @tbl where b=2 )AS b , (SELECT SUM(c) from @tbl where c=3 )AS c I ask one of my friend to make a single line query for this work

How to determine the effective permissions for a user of a SQL Server database through C#?

夙愿已清 提交于 2019-12-05 23:53:17
问题 When I say effective permissions, I'm referring to the permissions listed when you go into the properties of a database in SQL Server Management Studio, click "Permissions", and then click the "Effective" tab. So far, I have been able to determine the explicit permissions with the following code: using Microsoft.SqlServer.Management.Smo; ... DatabasePermissionInfo[] permissions = database.EnumDatabasePermissions("username"); However, I still need to obtain the effective permissions. In this

SQL Server 2008 R2 standard missing “Audits” folder in SSMS?

佐手、 提交于 2019-12-05 23:14:44
I will pre-cursor this with the fact that I am NOT a DBA! I am trying to set up auditing on an SQL Server 2008 R2 Standard edition, but the Audits folder is missing from the Security section. Is this a version issue associated with the "fine-grained auditing" that is only in the Enterprise and DataCenter editions? Any help is greatly appreciated! According to Features Supported by the Editions of SQL Server 2008 R2 auditing is only available in 2008 / 2008 R2 Enterprise / Datacenter. According to Features Supported by the Editions of SQL Server 2012 auditing has been split up in SQL Server

Split row based on start end date SQL Server

爷,独闯天下 提交于 2019-12-05 22:33:48
Let's say I have these values in a table Package | Start Date | End date --------------------------------- PKG123 | 01-02-2013 | 31-01-2016 PKG456 | 15-06-2010 | 14-06-2014 I want to write a select statement that should give me results like: Package | Start Date | End date ----------------------------------- PKG123 | 01-02-2013 | 31-01-2014 PKG123 | 01-02-2014 | 31-01-2015 PKG123 | 01-02-2015 | 31-01-2016 PKG456 | 15-06-2010 | 14-06-2011 PKG456 | 15-06-2011 | 14-06-2012 PKG456 | 15-06-2012 | 14-06-2013 PKG456 | 15-06-2013 | 14-06-2014 Is there a way to do it in TSQL? Please note that I am not

Better way to check condition instead of repeated Case When

大兔子大兔子 提交于 2019-12-05 19:59:18
This is my Tables: [Member]: { [Id], [UserId], [UserName], [Email], [Status_Id], [MemberType_Id] } [CustomerProfile] : { [Id], [Member_Id], [FirstName], [LastName], [SSN], [Gender], [PostalCode],[City_Id], [Address]} [DealerProfile]: { [Id], [Member_Id], [FirstName], [LastName], [SSN], [Gender], [StoreName], [PostalCode], [City_Id], [Address] } [ManagerProfile] { [Id], [Member_Id], [FirstName], [LastName], [SSN], [Gender] } [City]: { [Id], [Title], [Province_Id] } So I need to create a full view of all my members and related columns, I am going to start with the following select query: SELECT

“Between” operator generating bad query plan when using parameters

非 Y 不嫁゛ 提交于 2019-12-05 18:17:20
I have a simple dates table (Date, DateID) which contains a list of dates between 1-Jan-1900 and 31-Dec-2100. When selecting from the table using the between operator and hard-coded parameter values, I get a correct query plan with 3 estimated rows compared to 2 actual rows: select v.Date from Dates v where v.Date between '20130128' and '20130129'; However when replacing the hard-coded values with parameters, the query plan changes to a very poor plan, with over 6000 estimated rows and only 2 actual rows: select v.Date from Dates v where v.Date between @startdate and @enddate; The query plans

Convert string into xml and insert Sql Server

泄露秘密 提交于 2019-12-05 18:13:57
问题 We have a SQL Server 2008 R2 database table with XML stored in a column of VARCHAR data type. I now have to fetch some of the elements of the xml. So I want to first convert the xml stored as a VARCHAR data type, to an xml stored as xml data type. Example : Table A Id(int) , ProductXML (varchar(max)) Table B Id(int), ProductXML(XML) I want to convert the ProductXML from Table A into XML data type and insert into Table B . I tried using the CAST() and CONVERT() function as shown below : insert

How to drop all of the indexes except primary keys with single query

久未见 提交于 2019-12-05 18:00:21
I am planning to drop all of the indexes except the primary keys. I made the primary keys myself but all other indexes was suggestion of SQL Server. After dropping all indexes which are not primary keys, planning to use SQL Server profiler tuning template for database tuning advisor and create indexes. With this way planning to not have unused indexes or performance degrading indexes. How logical is this ? Thank you. DECLARE @sql NVARCHAR(MAX) = N''; SELECT @sql += N'DROP INDEX ' + QUOTENAME(SCHEMA_NAME(o.[schema_id])) + '.' + QUOTENAME(o.name) + '.' + QUOTENAME(i.name) + ';' FROM sys.indexes

FLWOR in Sql server count number of hits

∥☆過路亽.° 提交于 2019-12-05 17:47:30
I am using SQL Server 2008 R2. My problem is that I want to count number of hits that i receive from XQuery query using FLWOR. For each hit, I want a consecutive number, like: 0,1,2,3,4... My query: select @xml.query('for $s at $count in /Root/Persons/Person return <Person ID="{$count}">{$s}</Person>') The only problem here is this is not supported in SQL Server and I receive an error: Msg 9335, Level 16, State 1, Line 16 XQuery [query()]: The XQuery syntax 'at' is not supported. I've also tried with let keyword and define new variable but I don't know how to increase value of that variable