sql-server-2012

Max date won't work, alternative?

你。 提交于 2019-12-13 03:39:44
问题 I read through some of the answers but couldn't find the right answer for the following question. I have the below query that runs: SELECT mbr_src_code as 'C', cst_recno as 'ID', ind_first_name as 'FN', ind_last_name as 'LN', cst_org_name_dn as 'Company', cst_ixo_title_dn as 'Title', MAX(inv_trx_date) as 'Latest Transaction', inv_add_user as 'User', pyd_type as 'Type', bat_code as 'Code', mbr_add_user 'Add User', mbr_rejoin_date as 'rejoin', mbt_code, adr_state as 'state', adr_country as

Pandas to_sql 'append' to an existing table causes Python crash

杀马特。学长 韩版系。学妹 提交于 2019-12-13 03:34:45
问题 My problem is essentially this: When I try to use to_sql with if_exists = 'append' and name is set to a table on my SQL Server that already exists python crashes. This is my code: @event.listens_for(engine, 'before_cursor_execute') def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany): if executemany: cursor.fast_executemany = True df.to_sql(name = 'existingSQLTable', con = engine, if_exists = 'append', index = False, chunksize = 10000, dtype = dataTypes) I

Update one by one records using loop in SQL Server

大憨熊 提交于 2019-12-13 03:34:40
问题 I have Sector ID, need to update sector name and sector short name as 'Sector 1' and 'Sector 1' for each sector id respectively using loop. How can I achieve this? SectorID SectorName SectorShortName --------------------------------------- 1 METALS METAL 2 FINANCIAL SERVICES FINAN 3 IT IT 4 SERVICES SERVI 5 PHARMA PHARM 6 CHEMICALS CHEMI 7 TEXTILES TEXTI 8 ENERGY ENERG 9 INDUSTRIAL MANUFACTURING INDUS 10 CEMENT & CEMENT PRODUCTS CEMEN 11 CONSUMER GOODS CONSU 12 CONSTRUCTION CONST 13 TELECOM

Powershell error setting Environment variable for an SSIS package execution

让人想犯罪 __ 提交于 2019-12-13 03:20:11
问题 My Powershell script executes an SSIS package, but first over-rides an Environment variable. The Alter method on the EnvironmentInfo object fails with a generic error message: "Operation 'Alter' on object [EnvironmentInfo[@Name='MyVariable']' failed during execution." I also tried removing the environment variable and changing the Project parameter, but received the same error on the Alter method for the Project object. I suspect this is either 1) a shortcoming of using the 32-bit version of

Loop through each value to the seq num

隐身守侯 提交于 2019-12-13 03:14:30
问题 I have below data and want to create sequence number for each ID by adding 29 days to Start Date. i.e. for ID 1, look for minimum(start date) that will be seq num 1 and then add 29. this will be Seq Num 2 and then go on till we loop through each Auth ID. each time look for max(end date) for each ID. when this loop reaches that value stop it for each value. ID StartDate EndDate 1 2017-01-01 2017-01-15 1 2017-01-15 2017-02-14 2 2017-01-01 2017-01-15 2 2017-01-05 2017-03-05 2 2017-01-10 2017-02

Can I use SQLCLR stored procedure to update a column of a database table ( using some compiled dll)

血红的双手。 提交于 2019-12-13 02:50:25
问题 I wanted to update the values of a few columns of a database table, using queries or stored procedure, but wanted to use my C# library to alter the value. For eg, I want the columns A,B,C of table T to be replaced with Encrypt(A), Encrypt(B) and Encrypt(C) where Encrypt is a part of a C# library. I could have done it in a simple console application, but I have to do this process for a lot of columns in lot of tables. Could I use a SQLCLR stored procedure / query to do this process in SQL

How to eliminate Claims with ClaimStatus = 1 based on Activity Date. SQL Server 2012

时间秒杀一切 提交于 2019-12-13 02:13:23
问题 I have 3 different claims in my dataset. ClaimStatus can be only 1 or 0. Which indicates Open (0) or Closed (1). How to eliminate those claims that have the last ClaimStatus = 1 . I tried to use Last_Value function in my WHERE clause but got an error: Windowed functions can only appear in the SELECT or ORDER BY clauses Query result should return only Claim2 , because ClaimStatus is still open: Code: declare @TempTable table ( ClaimNumber varchar(50), ActivityID int, Activity varchar(50),

ALTER DATABASE CURRENT - exception

自闭症网瘾萝莉.ら 提交于 2019-12-13 01:50:35
问题 I have a stored procedure where i change DB properties . It uses ALTER DATABASE CURRENT in the script. But i found that this works fine in 2012 MSSQL version , but gives an exception in the older version. How to solve this problem ? sample Script content: ALTER DATABASE CURRENT SET ANSI_PADDING OFF GO Error: Incorrect syntax near the keyword CURRENT 回答1: You can use anonymous block with sp_executesql - declare @db_name varchar(64) declare @stat_sql nvarchar(256) begin select @db_name =

I want to connect SQL Server database which is in .bak format to the ASP.net web application that I have created

偶尔善良 提交于 2019-12-13 01:42:18
问题 I have created an ASP.Net web application with SQL Server 2005 database on another computer. I want to transfer it to another PC. Therefore, I have copied the ASP.Net Project and also the SQL database in .bak format. I need to configure the application to connect to the database and need help to get the correct connection string. PS: the database created was by SQL Server 2005 and I need to deploy on SQL Server 2012 回答1: bak files are Sql Server backup files. You need to restore it into the

sql server running total with over, partition

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 01:24:12
问题 I am trying to calculate running total in following query select a.ICode, MONTH(a.VDate), YEAR(a.vdate) , sum(isnull(a.qty, 0)) , sum(isnull(a.qty, 0)) OVER (partition by a.icode order by a.icode) AS 'total' from t_Stock as a group by a.ICode, MONTH(a.VDate), YEAR(a.vdate) order by a.icode, YEAR(a.vdate), MONTH(a.VDate) but I am getting an error: Msg 8120, Level 16, State 1, Line 3 Column 't_Stock.Qty' is invalid in the select list because it is not contained in either an aggregate function