sql-server-2005

How can evaluate more than once data from a query?

无人久伴 提交于 2019-12-13 03:41:49
问题 CREATE TABLE #Temp (VisitingCount int, [Time] int ) DECLARE @DateNow DATETIME,@i int,@Time int set @DateNow='00:00' set @i=1; while(@i<48) begin set @DateNow = DATEADD(minute, 30, @DateNow) set @Time = (datepart(hour,@DateNow)*60+datepart(minute,@DateNow))/30 insert into #Temp(VisitingCount,[Time]) values(0,@Time ) set @i=@i+1 end select Sum(VisitingCount)as VisitingCount, [Time] from #Temp group by [Time] Union All select count(page) as VisitingCount, (datepart(hour,Date)*60+datepart(minute

Warning: Null value is eliminated by an aggregate or other SET operation in Aqua Data Studio

你离开我真会死。 提交于 2019-12-13 03:38:53
问题 I have a problem when data is null and the warning has appear when the result is display. How to solve this problem?. How to change the null data to 0 when no data in the table?. This is my code:- SELECT DISTINCT c.username AS assigner_officer, d.description AS ticketcategory, (SELECT Count(closed) FROM ticket WHERE assigned_to = c.user_id AND closed IS NOT NULL GROUP BY assigned_to)closedcases, (SELECT Count(closed) FROM ticket WHERE assigned_to = c.user_id AND closed IS NULL GROUP BY

Does Sql Server Compress Database size on similar data

可紊 提交于 2019-12-13 03:33:29
问题 Just to find out my would be DB size on production environment, I just populated my tables with 1.5 million rows of nearly same data (Except Primary key). It currently shows 261 MB... Now, Whether I can rely on this, or since the Data is almost similar on all other columns the SQL server has compressed the size. ie. Will the size be different if the values in each rows are different... Further.. Does even columns will null values contribute to the size of the DB ? Thanks for your time... Edit

Fully qualified table names with SP_ExecuteSql to access remote server

倖福魔咒の 提交于 2019-12-13 03:32:37
问题 Trying to update a table on a linked server (SQL 2000/2005) but my server name will not be known ahead of time. I'm trying this: DECLARE @Sql NVARCHAR(4000) DECLARE @ParamDef NVARCHAR(4000) DECLARE @SERVER_NAME VARCHAR(35) SET @Sql = 'UPDATE @server_name_param.dba_sandbox.dbo.SomeTable SET SomeCol=''data''' SET @ParamDef = N'@server_name_param VARCHAR(35)' print @Sql exec sp_executesql @Sql, @ParamDef, @server_name_param=@SERVER_NAME Which returns this: UPDATE @server_name_param.dba_sandbox

How to address SqlConnection being closed from inside ExecuteReader?

拥有回忆 提交于 2019-12-13 03:27:39
问题 I have an open SqlConnection and code like this: using (var transaction = connection.BeginTransaction()) { using (var command = connection.CreateCommand()) { command.Transaction = transaction; command.CommandText = "MyQueryText"; using( var reader = command.ExecuteReader() ) { //read data } } } I've been experiencing some "impossible code" symptoms and subscribed to SqlConnection.StateChange event and now I've found that at some point the event is invoked with the following stack (state is

How to read a remote xml file from SQL Server 2005

邮差的信 提交于 2019-12-13 03:17:41
问题 Can I read a XML file from remote server such as http://dealer.somedomain.com/data/inventory.xml I need read and get data from this remote XML file and update some local tables. I use SQL Server 2005. Thanks in advance. 回答1: Your task can be split into two sub-tasks. Downloading the file over HTTP to your local PC (to a temporary folder). Importing the XML file into SQL Server. You can use SSIS for both. Once you look for "SSIS downloading over HTTP" or "SSIS downloading from website" you

Having trouble with this simple SQL Select statement

让人想犯罪 __ 提交于 2019-12-13 03:13:43
问题 I have two tables, A and B. Both have the exact same columns. I need to select all the items in TableA that ARE NOT in TableB. This is intersection, right? How can I do this? 回答1: assuming TableA and TableB have a primary key of name id. select TableA.* from TableA left outer join TableB on TableB.id = TableA.id where TableB.id is null; This will find all entries where table b does not have an instance of table a's id. 回答2: You could use the EXISTS clause SELECT * FROM TableA WHERE NOT Exists

Using Excel source on a machine without excel installed in SSIS

故事扮演 提交于 2019-12-13 03:08:56
问题 I have made an SSIS package that uses the Excel source to extract data from an Excel 2003 file and inserts it into SQL Server. When executed on production machine it gives and error of 'productleveltoolow'. Excel is not installed on the server. Can this error be due to this reason? 回答1: 'productleveltoolow' means the server does not have SSIS installed. http://blogs.msdn.com/michen/archive/2006/11/11/ssis-product-level-is-insufficient.aspx 回答2: Do you use a 64 bit operating system? In that

Problem in counting nulls and then merging them with the existing rows

自闭症网瘾萝莉.ら 提交于 2019-12-13 03:07:56
问题 Input: ID groupId RowID Data 1 1 1 W 2 1 1 NULL 3 1 1 NULL 4 1 1 Z 5 1 2 NULL 6 1 2 NULL 7 1 2 X 8 1 2 NULL 9 1 3 NULL 10 1 3 NULL 11 1 3 Y 12 1 3 NULL Expected Output GroupId NewData 1 2Y1,2X1,W2Z For every Null there will be a numeric count. That is if there are two nulls then the numeric value will be 2. The ddl is as under DECLARE @t TABLE(ID INT IDENTITY(1,1) , GroupId INT, RowID INT, Data VARCHAR(10)) INSERT INTO @t (GroupId, RowID,DATA) SELECT 1,1,'W' UNION ALL SELECT 1,1,NULL UNION

Why is this LINQ so much slower than its SQL counterpart?

旧城冷巷雨未停 提交于 2019-12-13 02:59:12
问题 I have the below LINQ to SQL method that takes an inordinate amount of time to execute yet its SQL counterpart is quite simple and fast. Am I doing something wrong in the LINQ part? I am just trying to return some data to display, read-only, in a Data Grid. I understand that if the tool doesn't fit don't use it and as such I could just do a SQL call here but I'd like to understand why there is such a difference. Below is the LINQ and then the SQL that it dumps. public static DataTable