sql-server-2008-r2

use a variable in the table name when renaming a table in SQL

折月煮酒 提交于 2020-01-03 17:31:32
问题 I am trying to rename a table in SQL Server 2008 R2 using the code below; declare @date varchar(8) set @date = convert( varchar(8), getdate(), 112) exec sp_rename 'LM_SM_Billing_and_Send_Data', 'LM_SM_Billing_and_Send_Data_@date' My intention is to rename the table with the current date appended. select convert( varchar(8), getdate(), 112) returns 20141219 but when I run the rename it names the table; LM_SM_Billing_and_Send_Data_@date instead of inserting the date I'm wondering if it is

Get IDENTITY value in the same T-SQL statement it is created in?

一个人想着一个人 提交于 2020-01-03 17:31:13
问题 I was asked if you could have an insert statement, which had an ID field that was an "identity" column, and if the value that was assigned could also be inserted into another field in the same record, in the same insert statement. Is this possible (SQL Server 2008r2)? Thanks. 回答1: You cannot really do this - because the actual value that will be used for the IDENTITY column really only is fixed and set when the INSERT has completed. You could however use e.g. a trigger CREATE TRIGGER trg

SQL Server “network-related or instance-specific error” once a day or so (perplexed!)

ぃ、小莉子 提交于 2020-01-03 17:08:03
问题 We are experiencing the same error as this StackOverflow Q ... System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period

Using foreign key in SQL server and DB locks

大城市里の小女人 提交于 2020-01-03 15:34:12
问题 I have been working with SQL Server for a long time I always use FKs and indexes when a logic connection between tables exist Example: MyTable1 { ID BIGINT IDENTITY (1, 1) NOT NULL, SomeData NVARCHAR(255) NOT NULL, MyFK BIGINT NULL -- this is a FK to MyTable2.ID } MyTable2 { ID BIGINT IDENTITY (1, 1) NOT NULL, SomeData NVARCHAR(255) NOT NULL } Now to the problem, When I execute some bulk update operations on MyTable1 that update MyFK, and in the same time execute an insert statements to

SQL Server - Add default constraints to all tables

大城市里の小女人 提交于 2020-01-03 15:33:04
问题 Is there a way to write a script that examines each table in the database, looking for a uniqueidentifier column named ID , and then add a DEFAULT constraint of NEWID() to the column if a DEFAULT constraint does not exist? 回答1: Edited per OP's commented clarification This script creates a DEFAULT constraint of NEWID() on any uniqueidentifier columns named ID that do not already have a DEFAULT constraint. SET NOCOUNT ON DECLARE @tableVarId int DECLARE @alterSql nvarchar(MAX) DECLARE

SQL LIKE statement using using unicode characters does not show correct result

北城余情 提交于 2020-01-03 11:26:20
问题 I'm using SQL Server 2008 R2. I'm just wondering why this statement doesn't work correctly. For example: The statement WHERE CONTRACTORNAME LIKE '%á%' would gives me the correct result for every records containing "á". But the statement WHERE CONTRACTORNAME LIKE '%ạ%' would not gives any records even though in CONTRACTORNAME column have a tons of records containing this character. Any help? 回答1: Try using a Unicode search string: WHERE CONTRACTORNAME LIKE N'%ạ%' 来源: https://stackoverflow.com

SSIS 2012 date formats dmy vs mdy

半世苍凉 提交于 2020-01-03 08:53:23
问题 There are three SQL Servers: PROD (2008 R2) NEW_TEST (2012) NEW_PROD (2012) I am migrating a large number of SSIS packages from PROD to both NEW_TEST and NEW_PROD servers. Source data comes from flat text files Source DATE data is in the format of dd/mm/yyyy (i.e. 5th of November 2015 is stored as 05/11/2015). In SSIS, the definition of the DATE source column (text file) is Unicode string (DT_WSTR) and the target column (in DB table) data type is DATETIME so a type conversion happens between

How to insert PHP array values using an stored procedure SQL SERVER 2008 R2(mssql)

大憨熊 提交于 2020-01-03 08:53:21
问题 I have this array $REV = Array ( 0 => 240, 1 => 241, 2 => 242, 3 => 243, 4 => 249 ); and i'm using this code bellow to insert for now, stored each array's element in a row with $id, $userID, Type and Date if (!empty($REV)) { foreach ($REV as $val_rev) { $values_rev[] = "('" . $ID . "','REV','" . $val_rev . "','" . $IDUSER . "',GETDATE())"; } $values_rev_insert = implode(',', $values_rev); $query_rev = "insert into dbo.CCLine (ID,CCType,CSID,IdUSer,DateCreated)values" . $values_rev_insert;

SSIS 2012 date formats dmy vs mdy

怎甘沉沦 提交于 2020-01-03 08:53:13
问题 There are three SQL Servers: PROD (2008 R2) NEW_TEST (2012) NEW_PROD (2012) I am migrating a large number of SSIS packages from PROD to both NEW_TEST and NEW_PROD servers. Source data comes from flat text files Source DATE data is in the format of dd/mm/yyyy (i.e. 5th of November 2015 is stored as 05/11/2015). In SSIS, the definition of the DATE source column (text file) is Unicode string (DT_WSTR) and the target column (in DB table) data type is DATETIME so a type conversion happens between

How to insert PHP array values using an stored procedure SQL SERVER 2008 R2(mssql)

[亡魂溺海] 提交于 2020-01-03 08:52:49
问题 I have this array $REV = Array ( 0 => 240, 1 => 241, 2 => 242, 3 => 243, 4 => 249 ); and i'm using this code bellow to insert for now, stored each array's element in a row with $id, $userID, Type and Date if (!empty($REV)) { foreach ($REV as $val_rev) { $values_rev[] = "('" . $ID . "','REV','" . $val_rev . "','" . $IDUSER . "',GETDATE())"; } $values_rev_insert = implode(',', $values_rev); $query_rev = "insert into dbo.CCLine (ID,CCType,CSID,IdUSer,DateCreated)values" . $values_rev_insert;