sql-server-2008-r2

how to find out defragment index pages in sql server 2008 using script?

走远了吗. 提交于 2019-12-12 06:23:56
问题 Hi i am using SQL SERVER 2008 R2 and i wanted to know how to get the defragment index pages in size for particular object, index in sql server 2008 r2 using script. can some one please help me to get this. thanks! in adavanced. 回答1: Use this query: SELECT object_id, index_id, avg_fragmentation_in_percent, page_count FROM sys.dm_db_index_physical_stats(DB_ID('AdventureWorks'), OBJECT_ID('HumanResources.Employee'), NULL, NULL, NULL) 来源: https://stackoverflow.com/questions/11774870/how-to-find

using > in case statement causes syntax error

情到浓时终转凉″ 提交于 2019-12-12 06:14:46
问题 Using the below code gives me a incorrect syntax near '>' the data in the Long field looks like this: Review Body 3, Review body 6, Aprentice, I've been going around in cirlces for hours traying to sort this, is it becasue I'm using a text function (Right) in a calc. SELECT TOP 1000 [Id] ,[Short] ,[Long] ,CASE ISNUMERIC(RIGHT( grade.Long , 1 )) WHEN cast(RIGHT( shiftname.Long , 1 )as int) > 4 THEN 'Qualified' ELSE 'Unqualified' END as Grade FROM [RosterPro_Live].[dbo].[lookup_PostGrade] as

How to get desired result by combining two CTE's?

◇◆丶佛笑我妖孽 提交于 2019-12-12 06:03:26
问题 I have two CTE's,firstly ;WITH CTE AS (SELECT A.* , Row_NUMBER() Over (Partition by ID order by Date asc) RN FROM TABLE A) SELECT Sum(Weight) as IN_WT FROM CTE WHERE RN = 1 and name='dev1' and then ;WITH CTE AS (SELECT B.* , Row_NUMBER() Over (Partition by ID order by Date desc) RN1 FROM TABLE B) SELECT Sum(Weight) AS out_wt FROM CTE WHERE RN1 = 1 and name='dev1' Now I had a reuiremnt that the output should be combined and get in_wt,out_wt.I tried combining both the CTE's but didn't get the

Check Internet Connectivity from sql query/script…?

旧城冷巷雨未停 提交于 2019-12-12 05:46:40
问题 Can we check availability of internet from sql Script? I google'd a lot with no use. Any suggestion regarding this is highly appreciated. Thanks in Advance 回答1: You can do this with a SQL CLR UDF. Here is an example: [Microsoft.SqlServer.Server.SqlFunction] public static SqlBoolean HasConnectivity(SqlString url) { try { if (url.IsNull) { return false; } var httpRequest = (HttpWebRequest)HttpWebRequest.Create(url.ToString()); using(var response = (HttpWebResponse)httpRequest.GetResponse()) { /

Select Query giving output as ??????????? with different language text

∥☆過路亽.° 提交于 2019-12-12 05:38:35
问题 Why is this query giving me ???????? as output. Declare @Search NVARCHAR(MAX) = 'اختبار كتاب اللغة العربية' SET @Search = N''+ @Search select @Search Where as this one works fine :- Declare @Search NVARCHAR(MAX) = N'اختبار كتاب اللغة العربية' select @Search I want to make my query dynamic. Is there any other way I can do it? Dynamic in the sence I can pass anything in the @Search parameter. I have a .NET application where I will pass the string to be searched in the @Search parameter which

How to know the state of an sql instance in a c# program

社会主义新天地 提交于 2019-12-12 05:35:17
问题 I have one database with one mirror in high-safety mode (using a witness server at the moment but planing to take him out), this database will be used to store data gathered by a c# program. I want to know how can I check in my program the state of all the SQL instances and to cause/force a manual failover. is there any c# API to help me with this? info: im using sql server 2008 edit: I know I can query sys.database_mirroring but for this I need the principal database up and runing, I would

Is it possible to set a maximum value for a column in SQL Server 2008 r2

余生长醉 提交于 2019-12-12 05:31:58
问题 My question is pretty simple but I'm not sure if it's possible. Assume I have a table and it contains the column below PokemonHappiness smallint Is it possible to set a maximum value for that column? For instance if I set the maximum to 10000 and send a query like this --Assume that PokemonHappiness is equal to 9990 update mytable set PokemonHappiness = PokemonHappiness+50 it should become 10000 instead of 10040 Is this possible? 回答1: A trigger. I tested this. CREATE TRIGGER dbo.Table_2update

How to generate sql server 2012 scripts in sql server 2008 r2?

瘦欲@ 提交于 2019-12-12 05:19:06
问题 I have a script from SQL Server 2012 to create a database and I need to generate it in SQL Server 2008 R2. It create the database but no tables and views etc is created. This is my script: /* Deployment script for CMS This code was generated by a tool. Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. */ GO SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON; SET NUMERIC_ROUNDABORT OFF; GO :setvar

Relating More than two tables through foreign keys

社会主义新天地 提交于 2019-12-12 05:16:29
问题 create table Customer ( ID int not null primary key, Name varchar(30) not null ) create table Purchase ( ID int not null primary key, CustomerID int references Customer (ID), Description varchar(30) not null, Price decimal not null ) First above is an sql script through my sql server management studio to create two tables (Customer and Purchase).Then the following classes is added to the C# code as follows. [Table(Name = "Customer")] public class Customer { [Column(IsPrimaryKey = true)]

SQL Rank based on date

谁说胖子不能爱 提交于 2019-12-12 05:14:52
问题 I am trying to link a customer to a "peferred" merchant based on number of visits within the last 18 months, with the tiebreaker being the most recent visit date. I'm having a bit of trouble with the tiebreaker. If there are two records both ranked 1 based on # of visits for a certain MemberID, I want to set the IsFirst bit column to 1 on the record with the MAX(EncounterDate) for that MemberID. How should I go about doing this? 回答1: This may help you... This is Oracle query based on existing