sql-server-2008-r2

what is numeric(18, 0) in sql server 2008 r2

懵懂的女人 提交于 2019-12-04 09:52:13
问题 I found a table with this a column from this data type numeric(18, 0) what is that please? and why does 0 and 18 mean I already check this question Difference between numeric, float and decimal in SQL Server but couldn't understand it.\ can I add (-10) in that column? can I add all negative number in that column? can I add any positive number in that column? Update 1 This is a sample of the data I found in that column 100 263 13 2 9 4 3 3 28 15 33 16 135 50 64 60 100 500 150 Update 2 Is it

CASE THEN clause always evaluated

大憨熊 提交于 2019-12-04 09:18:51
I'm doing a SELECT which uses CASE to convert nvarchar values into a proper type, something like this: SELECT CASE WHEN @propType = 'money' THEN convert(money, datavalue) [...] ELSE datavalue END FROM [...] However, it seems the convert is always executed, even when @propType is not equal to money. Runnable example: declare @proptype nvarchar(50)= 'nvarchar' declare @val nvarchar(10) = 'test' select case @proptype when 'money' then convert(money, @val) else @val end Why is this, and how can I get around it? The MSDN documentation says this: The CASE statement evaluates its conditions

Stored Procedure runs fast after recompile

浪尽此生 提交于 2019-12-04 08:24:24
问题 I have a very weird issue with a stored procedure on SQL Server 2008 R2. Sometimes, about once every month, I have one procedure that becomes very slow, takes about 6sec to run instead of a few milliseconds. But if I simply recompile it, without changing anything, it runs fast again. It does not happen on all stored procedure, only one (there are a few hundreds on the server). My guess is when the sp is compiled, it is cached and this cache is reused every time I call it, and this cached

T-SQL join to get both mated and non mated start and stop records

被刻印的时光 ゝ 提交于 2019-12-04 08:21:55
I have a poorly designed table that I did not design and cannot fix/change because a 3rd party blackberry app that writes to it. The meat is that there is a start record and a stop record for tracking events with NO connection or validation that there is a match. The blackberry app does nothing to tie these records together. I have tried to create a join on its self and create temp tables with the begin and one with the end to full outer join them. The problem is that I have duplicate entries were the entry should be marked as having no mate. Existing data has rows with no mate on both the

Want to create a script to export Data and tables and views to a sql script

二次信任 提交于 2019-12-04 08:16:57
问题 Want to create a script to export Data and tables and views to a sql script. I have SQL Server 2008 r2. So far I've only been able to automatically generate an sqlscript for all tables and views. But the data wasn't included. OR is there any easier way to export data, tables, views, from one SQL Server to my ISP's SQL server? Regards Tea 回答1: If for some reason a backup/restore won't work for you, SSMS' Generate Scripts tool includes an advanced scripting option to include data: 回答2: Here are

How to rollback a transaction in a stored procedure?

我的未来我决定 提交于 2019-12-04 08:13:02
问题 Looking at the SQL Server Books Online, Microsoft seems to have an (incorrect) method of handling nested transactions in a stored procedure: Nesting Transactions Explicit transactions can be nested. This is primarily intended to support transactions in stored procedures that can be called either from a process already in a transaction or from processes that have no active transaction. The example goes on to show a stored procedure that starts its own transaction ("The procedure enforces its

Is this the correct way to use UNION ALL in a stored procedure?

偶尔善良 提交于 2019-12-04 08:07:53
Is this the correct way to UNION ALL in a stored procedure? ALTER PROCEDURE [GetHomePageObjectPageWise] @PageIndex INT = 1 ,@PageSize INT = 10 ,@PageCount INT OUTPUT ,@whereStoryID varchar(2000) ,@whereAlbumID varchar(2000) ,@wherePictureID varchar(2000) AS BEGIN SET NOCOUNT ON; SELECT StoryID , AlbumID , StoryTitle , NULL AS AlbumName , (SELECT URL FROM AlbumPictures WHERE (AlbumID = dbo.Stories.AlbumID) AND (AlbumCover = 'True')) AS AlbumCover , Votes , NULL AS PictureId , 'stories' AS tableName , NEWID() AS Sort INTO #Results1 FROM Stories WHERE StoryID IN (SELECT StringVal FROM

update a database table field with comma separated list from join

自闭症网瘾萝莉.ら 提交于 2019-12-04 07:55:21
I have two tables named Districts and Schools . The Districts table contains a column named Schools . I need to populate the Schools column of the Districts table from the corresponding Schools table, so that each row in the Districts table has a comma separated list of values of school names from the Schools table. How can I do this? Should I use an UPDATE query or a stored procedure? I only got as far as: SQL Fiddle Districts Table +------------+------+---------+ | DistrictId | Name | Schools | +------------+------+---------+ | 1 | a | | | 2 | b | | | 3 | c | | | 4 | d | | +------------+----

Entity Framework Not Creating Database

陌路散爱 提交于 2019-12-04 07:49:06
问题 Been playing around with the Code First feature of Entity Framework 4.1 using an ASP.NET MVC 3 project. However the database (SQL Server 2008 R2) does not automatically create the table mapping on application startup. Any ideas on how to make it do so? The project has only one POCO: namespace RIS.Models { public class Person { [Key] public virtual string NRIC { get; protected set; } public virtual string FirstName { get; protected set; } public virtual string MiddleName { get; protected set;

SQL Server 2008: How to query all databases sizes?

拈花ヽ惹草 提交于 2019-12-04 07:39:15
问题 I have MS SQL 2008 R2, 500 databases. What is the most efficient, easiest and 'modern' way to query all databases sizes. The output should have columns: DatabaseName DataFilesSize LogFilesSize 回答1: with fs as ( select database_id, type, size * 8.0 / 1024 size from sys.master_files ) select name, (select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB, (select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB from sys