sql-server-2008-r2

select statement working unexpectedly

大兔子大兔子 提交于 2019-12-25 02:43:23
问题 when i click SELECT TOP 1000 row from table then it only shows some records like 3 records but when i manually run query on same table then it shows all records like many 1000s records which i always want. Select * from dbo.HrEmployee why ? Help please, i'm using SQL SERVER 2012 回答1: It look like you have created two copies of the same database, the one is in the “intended” database and the second has been created in the master database. 3 records were then inserted into the intended table

Adding one more column externally in query

社会主义新天地 提交于 2019-12-25 02:43:12
问题 I have following query: WITH ctablee(mon, [<=15], [<=18], [<=20], [>20]) AS (SELECT * FROM (SELECT CONVERT(CHAR(4), [Data OUT (No Val#Vuoto)], 100) mon, [Gruppi Min (GG Flusso/Decorrenza-->Out)], Count([Gruppi Min (GG Flusso/Decorrenza-->Out)]) cnt FROM dbpratiche WHERE compagnia = 'GENERTEL' GROUP BY [Gruppi Min (GG Flusso/Decorrenza-->Out)], CONVERT(CHAR(4), [Data OUT (No Val#Vuoto)], 100) ) T PIVOT ( sum(cnt) FOR [Gruppi Min (GG Flusso/Decorrenza-->Out)] IN ([<=15], [<=18], [<=20], [>20]))

how to create temp table while Joining multiple tables that have to be PIVOT

六眼飞鱼酱① 提交于 2019-12-25 01:56:15
问题 I have similar 3-4 scripts for different tables to dynamically PIVOT as previously posted Dynamic Pivot (row to columns) Goals: - Create a excel file Joining all the fields from the PIVOTed tables(all the rows from each table) Steps: Create separate temp tables for each set (after Pivoting on different tables) JOIN all the temp tables on column ID SELECT columns from the resultset(all temp tables) **Would like to know if there is a better way to create a temp table using a procedure for

SQL Server 2008 R2 Install stuck

佐手、 提交于 2019-12-25 01:47:09
问题 When I try to install my SQL Server 2008 R2, it keeps getting stuck at SqlEngineDBStartConfigAction_install_configrc_Cpu64 I found in other issues that I should kill the msiexec process but I can't find it. What should I do? Thank you 来源: https://stackoverflow.com/questions/53363429/sql-server-2008-r2-install-stuck

How do I script procedures when generating a script with the SMO scripter?

邮差的信 提交于 2019-12-25 01:46:43
问题 I am trying to write a Powershell script to generate a SQL script that creates the stored procedures in my database. Here is what I have: [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')| out-null Function to-array ($c) { foreach($item in $c) { $result += @($item) } $result } $s = new-object ('Microsoft.SqlServer.Management.Smo.Server') "LOCALHOST" $scrp = new-object ('Microsoft.SqlServer.Management.Smo.Scripter') ($s) $dbs = $s.Databases $fa = $dbs["FinancialAid"]

how to write this SQL statement Update Where in?

混江龙づ霸主 提交于 2019-12-25 01:28:03
问题 Update [E1$] set [LR/Virtual/MW]='LR' , [Vir No#]=null where [Conc] , [Vir No#] in ( SELECT [Conc] , [Vir No#] FROM [E1$] where [Vir No#] is not null group by Conc , [Vir No#] having Count(LR)<28 ) 回答1: try this: Update E set [LR/Virtual/MW]='LR' , [Vir No#]=null from [E1$] E join (SELECT [Conc] , [Vir No#] FROM [E1$] where [Vir No#] is not null group by Conc ,[Vir No#] having Count(LR)<28 ) a on e.[Conc]=a.[Conc] and e.[Vir No#]=a.[Vir No#] 回答2: Try using parenthesis around ([conc], [Vir No#

Displaying multiple values into columns in sql server using pivot

回眸只為那壹抹淺笑 提交于 2019-12-25 01:06:01
问题 declare @t table ( driver varchar(20), roadband varchar(20), category varchar(20), points int ) INSERT INTO @T VALUES( 'Dan' ,'20 Mph','CAT1',58) INSERT INTO @T VALUES( 'Dan' ,'20 Mph', 'CAT2', 0) INSERT INTO @T VALUES( 'Dan' ,'20 Mph', 'CAT3', 0) INSERT INTO @T VALUES( 'Dan' ,'30 Mph', 'CAT1', 102) INSERT INTO @T VALUES( 'Dan' ,'30 Mph', 'CAT2', 30) INSERT INTO @T VALUES( 'Dan' ,'30 Mph', 'CAT3', 0) INSERT INTO @T VALUES( 'Dan' ,'40 Mph', 'CAT1', 6) INSERT INTO @T VALUES( 'Dan' ,'40 Mph',

Modify XML to Order Mid-level Complextype Elements by Name

孤街浪徒 提交于 2019-12-25 01:05:44
问题 Edit: See This link for follow-up question I have a large FOR XML EXPLICIT query in SQL Server 2008 R2 that creates an xml file, but it is failing to validate against my XSD schema because some of the mid-level elements appear in the wrong order. Here is an example XML file to show what I mean: <Things> <Thing> <Racecars> <Racecar> <Colour>Red</Colour> <Rockets>Y</Rockets> </Racecar> <Racecar> <Colour>Blue</Colour> <Rockets>N</Rockets> </Racecar> </Racecars> </Thing> <Thing> <Numbers> <Number

Get percentage of matching strings

和自甴很熟 提交于 2019-12-25 00:16:56
问题 I have two string to match and get the percentage of matching. Given: String 1: John Smith Makde String 2: Makde John Smith Used the following user defined scalar function. CREATE FUNCTION [dbo].[udf_GetPercentageOfTwoStringMatching] ( @string1 NVARCHAR(1000) ,@string2 NVARCHAR(1000) ) RETURNS INT --WITH ENCRYPTION AS BEGIN DECLARE @levenShteinNumber INT DECLARE @string1Length INT = LEN(@string1), @string2Length INT = LEN(@string2) DECLARE @maxLengthNumber INT = CASE WHEN @string1Length >

How to get first gap in a column containing sequential int values

心不动则不痛 提交于 2019-12-24 20:48:30
问题 I have a column in a SQL Server database table, there is a column containing integer values and I would like to get the max value unless there is a gap in the series, then I would like to get the first missing value. For example from the below table, I am looking to get value 4 1 2 null 3 The above is simple, however if the table contains data like below, how can I find which id I am missing, in this case it would be 8 1 3 2 4 null 5 7 6 null 10 9 ////////////////// Edit: I Initially