sql-server-2012

How to change the query to give last 15 weeks of data instead of last 15 days from the SQL Server

百般思念 提交于 2019-12-12 06:49:01
问题 The following query gives playing time of the users from the database on daily basis for the last 15 days. It adds 0 if no game is played. Now I want to get the data of playing time on weekly basis and 0 if no game is played in the whole week. So I want the query to give the last 15 weeks of data. Here is the daily query. CREATE PROCEDURE [dbo].[spGetPlayingTimeOfthepeoplesPerDay] @email NVARCHAR(50) AS BEGIN SET NOCOUNT ON; DECLARE @MinDate DATE ,@MaxDate DATE ,@LastXDays INT SELECT

One of the identified items was in an invalid format - Microsoft.SqlServer.Type

我们两清 提交于 2019-12-12 06:36:27
问题 I'm trying to retrieve geography data from my SQl Server 2012 DB with: new SqlDataAdapter("SELECT [SpatialColumn] FROM [SpatialTable]", myConnection).Fill(myDatatable); When the data is a Sql Server 2008 geography type such as Polygon , it's all working fine. But when the type is the new CurvePolygon then that line of code crashes with the error: System.FormatException occurred Message="One of the identified items was in an invalid format." Source="Microsoft.SqlServer.Types" StackTrace: at

Create and execute function in SQL Server

我们两清 提交于 2019-12-12 06:33:55
问题 I have four tables: dbo.Projects dbo.Locations (id, location name) dbo.Purpose (id, Purposename) dbo.Types (id, typname) I have a search criteria, this criteria is filled with data from database tables: locations , purpose and types . I want to create a function that returns table with search result from projects dependent on other tables. I have created one but it does not do what I need: ALTER FUNCTION SearchProjects ( @location nvarchar(50), @purpose nvarchar(50), @type nvarchar(50) )

TSQL Distinct Counts

℡╲_俬逩灬. 提交于 2019-12-12 06:22:36
问题 I have a table that looks like this: ID SuppressionTypeID PersonID ------------------------------ 1 1 123 2 1 456 3 2 456 I want to get a rolling count (distinct people) rather than a normal group by count. e.g. not this: SuppressionTypeID Count --------------------------- 1 2 2 1 This: SuppressionTypeID RecordsLost ---------------------------------- 1 2 2 0 The latter being zero as we lost person 456 on suppresiontypeid 1. Thanks in advance. 回答1: You may need to use a temporary table or a

Get last generated id asp.net

ぃ、小莉子 提交于 2019-12-12 05:47:42
问题 So I have 2 Tables in one Database (Table1 and Table2). What I want to do is to get the last generated ID (which is primary key) from the first table (Table1) and add it to another table (Table2). For example. The Last generated ID from Table1, column NRRENDOR is 25 (I have deleted the rows that's why it shows 22, it is primary key). If I add a row to Table1 it will generate number 26 on column NRRENDOR (First picture). But when number 26 is added to column NRRENDOR from Table 1, I want it to

TransactionScope and method call that uses the same connection

末鹿安然 提交于 2019-12-12 05:37:28
问题 I'm using TransactionScope to make a method that contains multiple sql statements transactional. Now i need to call a second method that also uses the same connection and i receive following exception at connection.Open() : Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool. So this is the pseudo-code: public static void Method1() { using

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

Join two tables to get matching records and unmatched records from Table 1

旧时模样 提交于 2019-12-12 05:11:29
问题 Scenario: I have 2 tables namely Coverage and Product Coverage Table: CId,CName,CType,CMessage,CDate,CoverageProductId Product Table: PId,CName,CType,CMessage,PDate,CoverageProductId By using CoverageProductId i am relating 2 tables. I need to get 3 columns CName,CMessage and CoverageProductId from both tables Condition Below, Get 3 columns values from Product table if both table CoverageProductId matches. Get 3 columns values from Coverage table if both table CoverageProductId not matches.

Generate view with X and Y from geometry type

让人想犯罪 __ 提交于 2019-12-12 05:04:04
问题 In sql-server-2012 I want to generate view with all points from geometry type. How can I do this? View example GeomKey | X | Y --------+----+----- 1 | X1 | Y1 1 | x2 | Y2 2 | x1 | Y1 Example in Oracle with sys.SDO select c.ngeometrykey, z.* from gis_map.mp_geometry c , table(sdo_util.getvertices(c.geometry)) z 回答1: I don't think you can do this in a view but you can create a table-valued user defined function (a function that returns a table) to get what you want. This example uses a table

Join tables from 2 datasets

谁说我不能喝 提交于 2019-12-12 04:58:46
问题 I have 2 data sets: 1) SELECT LocId from map_Sites ms inner join map_WaterSystems mw on mw.SiteId = ms.SiteId inner join map_Locations ml on mw.SysID = ml.SysID where ms.SiteId = 344 and LocId <> 9604 The result of this data set is: LocId 9605 9606 Here is the second data set: select dl.LocId, dl.ParamID, dl.alertNumExceed, dl.upperAlarm, dl.lowerAlarm, dl.alertOn, dl.EntryUserID, dl.ParamOrder from data_LocParams dl where LocId = 9604 The result of this dataset is LocId ParamID