sql-server-2008-r2

Search of table names

社会主义新天地 提交于 2019-12-04 07:29:44
问题 I use the following to search for strings in my stored procedures: use DBname SELECT Name FROM sys.procedures WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%xxx%' Is it easy to amend the above so that it searches Table names in a specific db "DBname" ? 回答1: I'm using this and works fine SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%%' 回答2: select name from DBname.sys.tables where name like '%xxx%' and is_ms_shipped = 0; -- << comment out if you really want to see them 回答3: I am

Dynamic case statement using SQL Server 2008 R2

流过昼夜 提交于 2019-12-04 06:50:44
问题 I have the following case statement as shown below: Example: I have the case statement : case cola when cola between '2001-01-01' and '2001-01-05' then 'G1' when cola between '2001-01-10' and '2001-01-15' then 'G2' when cola between '2001-01-20' and '2001-01-25' then 'G3' when cola between '2001-02-01' and '2001-02-05' then 'G4' when cola between '2001-02-10' and '2001-02-15' then 'G5' else '' end Note : Now I want to create dynamic case statement because of the values dates and name passing

Adding data to column

假装没事ソ 提交于 2019-12-04 06:35:29
问题 i have written this query to show total working time and overtime of an employee on particular date (if he has came). i want if for a particular date person's INtime and OutTime are empty then put 00:00 in his intime, outtime, totalworkingtime, overtime e.g. it's sunday so obviously no InTime and OutTime then it should show 00:00 in time columns. Note: dates are only entered if person InTIme is mentioned otherwise no DateVisited. e.g. EmplID EmplName ShiftID intime Outtime totalworking

How do UPDATE locks prevent a common form of deadlock?

。_饼干妹妹 提交于 2019-12-04 06:33:07
The SQL Server books online say that UPDATE locks prevent a common form of deadlock: Update Locks Update (U) locks prevent a common form of deadlock. How do they prevent a common form of deadlock? What do i mean by that? A common form of deadlock is when two processes attempt to escalate from a Shared (S) lock (i.e. read lock ) to a Exclusive (X) lock: Process A Process B ======================== ======================== Acquire Shared lock Acquire Shared lock Attempt to escalate to X Escalation waits on B Attempt to escalate to X Escalation waits on A Deadlock . Both processes are waiting on

how to pass default value to date parametere in storedprocedure - Sqlserver 2008?

青春壹個敷衍的年華 提交于 2019-12-04 06:30:00
问题 Here it is my stored procedure: ALTER proc [dbo].[allrecp] @peid int=0, @pename varchar(20)='', @pdes varchar(20)='', @pdoj date='1111-1-1', @sal money=0, @dept int=0, @loc int=0,@i int=0 as begin if(@i=1) begin insert into Employee values(@pename,@pdes,@pdoj,@sal,@dept,@loc) end if(@i=2) begin update Employee set ENAME=@pename,DESEGNATION=@pdes,DOJ=@pdoj,SALARY=@sal,DEPTID=@dept,LOCATIONID=@loc WHERE EMPID=@peid end if(@i=3) delete EMPLOYEE where EMPID=@peid end And my c# code is: private

STContains on Geography column

时光怂恿深爱的人放手 提交于 2019-12-04 06:28:43
问题 I have a bus point in Lat/long (geography). I want to check where my bus point (lat/long) lies in a region. My region is a set of lat/long points. I have lat/long of a region (Outline of the lat/longs which makes a region) in geography form. Now I have one point lat/long and I want to identify if that point lies inside my region. How can I do that? 4000 points make an outline of a region and one point is to check if that exist in that region or not. How will I check that? I think I can use

SAS Date Formats Incompatible with SQL Server Date

筅森魡賤 提交于 2019-12-04 06:24:00
问题 I'm fairly new to SAS and recently we migrated some of our SAS datasets to a SQL Server table but we are still using SAS to do our analysis. I have run into a problem when SAS is trying to bring in the data from the SQL Server table and have SAS check if the srv_edt date is between the SAS dates of dos_beg_dt1 and dos_end_dt1. When SAS tries to compare the dates I get an error of: ERROR: WHERE clause operator requires compatible variables. The dos_beg_dt1, dos_end_dt1, and srv_edt (SQL date

Matrix result using SQL Server 2008 R2

北城以北 提交于 2019-12-04 06:10:36
问题 I have a table as shown below: Example : CREATE TABLE matrix ( a VARCHAR(10), b VARCHAR(10) ); INSERT INTO matrix VALUES('A','H') INSERT INTO matrix VALUES('B','I') INSERT INTO matrix VALUES('C','J') INSERT INTO matrix VALUES('D','K') INSERT INTO matrix VALUES('E','L') INSERT INTO matrix VALUES('F','M') INSERT INTO matrix VALUES('G','N') INSERT INTO matrix VALUES('A','M') SELECT * FROM matrix; Looks like: a b ------- A H B I C J D K E L F M G N A M Now I want to show the result in the

What is the best way to push inserted data out of SQL Server to an application?

不问归期 提交于 2019-12-04 06:06:48
I would like to use some mechanism within SQL Server (or one of its services) to push change messages out (via UDP, for example, but TCP is OK, too) when rows get inserted into a table. I would like for these messages to be more than notifications of change, but to actually contained the changed data. Is there a mechanism that comes with SQL Server 2008 R2 to do this? I've heard of Service Broker and Extended Events, but am not sure that these are the right tools for the job when it comes to getting near real time data pushed out of SQL Server to another app that needs to update its internal

Data lost from .mdf file as I exit application

倖福魔咒の 提交于 2019-12-04 05:53:21
问题 Recently I work on SQL Server 2008 R2 database. I create database and attach .mdf file of same database in my application with some default data in it . Run application default data coming properly. Now I insert, update some data in my application and its works fine. But as I exit application and again run application lastly added and updated data get lost but default data coming proper as earlier. Please help. Why new 回答1: As mention by @Henk , @Microtechie , I scan my project folder and