sql-server-2005

Validate data before uploading through SSIS

前提是你 提交于 2020-01-02 10:06:33
问题 I have a SSIS package to upload data from Excel file into an Sql Server 2005 table. The excel file will have varied lines of data ranging from 20k - 30k lines. The upload works fine, when all the data are correct. But obviously fails when there is a small problem even in a single row. Examples like mandatory values presented null, inconvertable values (data type mismatch) etc. I want to validate the excel file before the upload and want to tell the user which row and column has got the error.

Troubleshooting Service Broker: initiator database stuck CONVERSING/NOTIFIED

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 09:58:26
问题 We are developing an application that will use service broker to transfer messages from one database to another. SourceDB is used by an existing application from which we are siphoning off some data. TargetDB is used only by this application and processes/distributes the data we need. We are only using one type of contract and both DBs are on the same server. We have set up identical message types and contracts on both, and respective initiator and target queue/service. On both databases:

Creating a Function in SQL Server with a Phone Number as a parameter and returns a Random Number

允我心安 提交于 2020-01-02 09:41:43
问题 I am hoping someone can help me here as google is not being as forthcoming as I would have liked. I am relatively new to SQL Server and so this is the first function I have set myself to do. The outline of the function is that it has a Phone number varchar(15) as a parameter, it checks that this number is a proper number, i.e. it is 8 digits long and contains only numbers. The main character I am trying to avoid is '+'. Good Number = 12345678 Bad Number = +12345678. Once the number is checked

Implicit conversions and rounding

亡梦爱人 提交于 2020-01-02 09:33:13
问题 Just come across an interesting one: declare @test as int set @test = 47 select @test * 4.333 returns 203.651 declare @test as int set @test = 47 declare @out as int set @out = (select @test * 4.333) select @out returns 203 declare @test as int set @test = 47 declare @out as int set @out = round((select @test * 4.333),0) select @out returns 204 Now I know why it does this. Its because there is an implicit conversion from decimal to int, therefore the decimal places need chopped off (hence 203

Implicit conversions and rounding

孤街浪徒 提交于 2020-01-02 09:31:30
问题 Just come across an interesting one: declare @test as int set @test = 47 select @test * 4.333 returns 203.651 declare @test as int set @test = 47 declare @out as int set @out = (select @test * 4.333) select @out returns 203 declare @test as int set @test = 47 declare @out as int set @out = round((select @test * 4.333),0) select @out returns 204 Now I know why it does this. Its because there is an implicit conversion from decimal to int, therefore the decimal places need chopped off (hence 203

Performing multiplication in SQL SERVER(SET BASED APPROACH)

纵然是瞬间 提交于 2020-01-02 09:24:50
问题 Suppose I have a table like the following: tblNumbers Numbers 4 5 3 6 Using SET BASED approach how can I perform a multiplication so the output will be: Output 360 N.B~ There is no hard and fast rule that there will be only four numbers, but I'd prefer the answer to be using a CTE and/or correlated subquery. 回答1: You can use logarithms/exponents that take advantage of the mathematical fact that: log(a*b*c...*n)=log(a)+log(b)+log(c)...+log(n) Therefore you can use the sum function to add all

SQL Server 2005 percentage in parenthesis in pivot table

依然范特西╮ 提交于 2020-01-02 08:56:09
问题 This is a follow up question from here. I have some output and was able to add a total column but now I need to use the column to add percentage like this: | LESSONID RESPONSE COUNT-> | 0 | 1 | 2 | 3 | 4 | N | --------------------------------------------------------------------------------------- |lesson1 | 1 (20%) | 1 (20%) | 1 (20%) | 1 (20%) | 1 (20%) | 5 | |lesson2 | 1 (20%) | 1 (20%) | 1 (20%) | 2 (40%) | 0 | 5 | |lesson3 | 1 (20%) | 1 (20%) | 0 | 3 (60%) | 0 | 5 | |lesson4 | 0 | 1 (20%)

SQL Server 2005 percentage in parenthesis in pivot table

独自空忆成欢 提交于 2020-01-02 08:56:08
问题 This is a follow up question from here. I have some output and was able to add a total column but now I need to use the column to add percentage like this: | LESSONID RESPONSE COUNT-> | 0 | 1 | 2 | 3 | 4 | N | --------------------------------------------------------------------------------------- |lesson1 | 1 (20%) | 1 (20%) | 1 (20%) | 1 (20%) | 1 (20%) | 5 | |lesson2 | 1 (20%) | 1 (20%) | 1 (20%) | 2 (40%) | 0 | 5 | |lesson3 | 1 (20%) | 1 (20%) | 0 | 3 (60%) | 0 | 5 | |lesson4 | 0 | 1 (20%)

How to change a column to an IDENTITY column and preserve the data?

假如想象 提交于 2020-01-02 08:34:32
问题 I had a column which was IDENTITY(1,1). All rows had been numbered consecutively. I did not add or remove any rows. I removed the identity property on this column. Now, I want it back. I think i can reset it to identity with seed = biggest number in existing table. Could any problems arise if I do this ? 回答1: From MSDN SQL Server forum - You have 2 options: Create a new table with identity & drop the existing table Create a new column with identity & drop the existing column. *But take

SQL script to change all table references in all stored procedures

二次信任 提交于 2020-01-02 08:23:09
问题 I have created a new database with copies of existing tables but changed the names of these tables, is there a SQL script that I can run (maybe using SysObjects) to change all references to these tables in all stored procedures? 回答1: DO NOT RELY ON INFORMATION_SCHEMA.ROUTINES because ROUTINE_DEFINITION is only nvarchar(4000) . You need to sys.sql_modules where definition is nvarchar(max) try any of these to find the procedure that you need to modify: SELECT DISTINCT LEFT(s.name+'.'+o.name,