sql-server-2008-r2

T-SQL Regex for social security number (SQL Server 2008 R2)

微笑、不失礼 提交于 2019-12-24 05:37:08
问题 I need to find invalid social security numbers in a varchar field in a SQL Server 2008 database table. (Valid SSNs are being defined by being in the format ###-##-#### - doesn't matter what the numbers are, as long as they are in that "3-digit dash 2-digit dash 4-digit" pattern. I do have a working regex: SELECT * FROM mytable WHERE ssn NOT LIKE '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]' That does find the invalid SSNs in the column, but I know (okay - I'm pretty sure) that there is a

How to show the overall percentage of participation of each division in all sent quizzes?

可紊 提交于 2019-12-24 05:08:08
问题 I am a new web developer and I am developing a simple training management system which provides the users with quizzes. The system developed using ASP.NET and MS SQLServer. Now, I need to come up with a query that shows the percentage of participation of each division in all the offered safety quizzes (which means quizzes with IsSent = true). I have the following database design: Employee Table: Username, Name, DivisionCode Divisions Table: SapCode, Divison Quiz Table: QuizID, Title,

Update multiple rows without looping

谁说我不能喝 提交于 2019-12-24 04:26:09
问题 I want to update multiple rows at once in a update statement without using loop. I have the following table with some records as shown below: Table: create table test ( col1 int, col2 int, col3 varchar(20), col4 datetime, name varchar(max) ); Insertion: insert into test values(111,999,'A101','2014-01-01',''); insert into test values(112,998,'A102','2014-01-02',''); insert into test values(113,997,'A103','2014-01-03',''); insert into test values(114,996,'A104','2014-01-04',''); insert into

SQL Server - Reference a column by name in aggregate function

青春壹個敷衍的年華 提交于 2019-12-24 03:43:40
问题 Our application uses a series of tables with many varchar(1000) columns in them. During development of the system, that was considered to be more than enough space for the users to enter text. However, now we're encountering problems with text being cut off, so it seems like some users are entering more text that it can hold. However, I believe that there's rampant misuse of these fields, and I want to see which columns are being used. From a different question that was answered here on SO, I

Console application can't connect to sql server instance from server, but can from local machine

一世执手 提交于 2019-12-24 03:13:15
问题 I have a few asp.net web applications running on a dedicated server.. For one of the websites, I am doing a maintenance task of upgrading all user uploaded images to new naming convention. I wrote a small, simple console application to do that job. I put the connection string in my app.config like so: <add key="CS" value="Data Source=1.1.1.1;Initial Catalog=MyDatabase;User ID=usr; Password=pwd" /> Of course, the details here are dummy they are not actually MyDatabase etc... but I do connect

how to add a column at a specific position in a table? [duplicate]

主宰稳场 提交于 2019-12-24 02:37:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: SQL Server 2008 : Cannot Insert new column in the middle position and change data type Hi i am using SQL SERVER 2008 & 2008 R2 i would like to add a column in a table at a specific position using alter command. is there any way keyword using which we can add a column at a specific position ? thanks! in adavanced. 回答1: Not very easy in sql server.. I think the best way is to add the column at the end of the table

Is IN with the multiple of the same values slower?

匆匆过客 提交于 2019-12-24 02:29:25
问题 For example, is this noticeably slower: DELETE FROM [table] WHERE [REOID] IN ( 1, 1, 1, 2, 2, 1, 3, 5) Than this: DELETE FROM [table] WHERE [REOID] IN ( 1, 2, 3, 4) SQL Server 2008 R2. Thanks! 回答1: Most engines would eliminate duplicates in the constant IN list on parsing stage. Such a query would parse marginally slower than that with a non-duplicated list, will produce the same plan and with most real-world scenarios, you will hardly notice any difference. 来源: https://stackoverflow.com

SSRS range bar chart, different color when no data

有些话、适合烂在心里 提交于 2019-12-24 01:59:16
问题 I am looking to change the color in the "gaps" in the range chart that I have built. Essentially I am trying to build a visualization for the staff to see the availability on bays. The red markings mean the bay is booked, I wanted green then to be in between the red to highlight free bays. Occupied bays: I suspect I need to go back to my dataset and add in some date tables to show "null data" to allow a "switch" to work, but I thought someone might know if I could change this without going

SQL Server 2008 R2 Inner Join Fails to match varchar fields because it contains special characters

主宰稳场 提交于 2019-12-24 01:54:35
问题 We are using Microsoft SQL Server 2008 R2 for one of our Classic ASP applications. We have two tables: TableA TableB TableA has the following columns: InstName(varchar[1024]) TableB has these columns: InstitutionName(varchar[1024]) However, we came across some data like the following TableA InstName with value University of Nantes [ Universites de Nantes ] TableB InstitutionName with value University of Nantes [ Universites de Nantes ] We need to run inner join select queries on the said 2

Using table-valued function in update statement

♀尐吖头ヾ 提交于 2019-12-24 01:47:37
问题 I'm trying to execute the following update statement: Update belege2 Set Preis_Einh = x.Preis, Aktion=x.Aktion, PreisHerk = x.PreisHerk FROM dbo.GetPreis(belege2.prodkey, belege2.Anzahl) x where belege2.Beleg_Nr = 13599 SQL Server displays the following errors: Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "belege2.prodkey" could not be bound. Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "belege2.Anzahl" could not be bound. Is this not supported? Is there a