sql-server-2008-r2

Get the latest records per Group By SQL

浪尽此生 提交于 2021-01-27 12:40:42
问题 I have the following table: ----------------------------------------------------------- ID oDate oName oItem oQty oRemarks ----------------------------------------------------------- 1 2016-01-01 A 001 2 2 2016-01-01 A 002 1 test 3 2016-01-01 B 001 3 4 2016-01-02 B 001 2 5 2016-01-02 C 001 2 6 2016-01-03 B 002 1 7 2016-01-03 B 001 4 ff. I want to get the latest record for each name. So the result should be like this: ----------------------------------------------------------- oDate oName

stored procedure parameter values logging

纵然是瞬间 提交于 2021-01-27 07:10:31
问题 Is there a way to check when and with what parameter values a stored procedure has been executed in SQL Server 2008 R2? 回答1: As usr said there is no way to do this at all, but you can do this as workaround, which I did in my projects. Create a log table and implement in each procedure a INSERT INTO log_table statement where you insert time with GetDate() , procedure name and logged user. This table you can seek for your informations then. This for sure only works for the future and not if you

losing null values filtering sql query results using where

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-31 05:42:13
问题 I have a complex query which joins more than 7 tables. After the joins, I would like to filter the result of my query . Here is something that I observed. When I do a where clause where X.Name != 'xxx' and XY.Product != 1 I get the filtered results , but all the null values for the X.Name and XY.Product also disappear from my result. I would like to retain the null values. I also tried : and X.Name != 'xxx' and XY.Product != 1 I removed the where clause totally and put in an and , but I dont

Drop column if exists in SQL Server 2008 r2

和自甴很熟 提交于 2020-12-30 06:17:08
问题 I am using SQL Server 2008 R2. I want to drop the column if it is already exists in the table else not throw any error. Tried: ALTER TABLE Emp DROP COLUMN IF EXISTS Lname; Error: Incorrect syntax near the keyword 'IF'. By searching I came to know that, this option is available from 2016. What is the alternative in the SQL Server 2008 R2? 回答1: IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Emp' AND COLUMN_NAME = 'Lname' AND TABLE_SCHEMA='DBO') BEGIN ALTER TABLE Emp

Drop column if exists in SQL Server 2008 r2

对着背影说爱祢 提交于 2020-12-30 06:11:35
问题 I am using SQL Server 2008 R2. I want to drop the column if it is already exists in the table else not throw any error. Tried: ALTER TABLE Emp DROP COLUMN IF EXISTS Lname; Error: Incorrect syntax near the keyword 'IF'. By searching I came to know that, this option is available from 2016. What is the alternative in the SQL Server 2008 R2? 回答1: IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Emp' AND COLUMN_NAME = 'Lname' AND TABLE_SCHEMA='DBO') BEGIN ALTER TABLE Emp

How to allow temporary tables to accept null values

五迷三道 提交于 2020-12-08 10:52:34
问题 If you create temp tables using "insert into" in SQL Server it uses the first insert to determine whether a column accepts null value or not. if the first insert has null value the column become nullable otherwise it will be non-nullable. Is there a way to create temp tables using "insert into" to accept null values? Example This works without any problem Select 'one' as a , null as b into #temp insert into #temp Select 'two' as a , 500 as b However this throws "Cannot insert the value NULL

Fulltext search multiple columns for multiple search terms

萝らか妹 提交于 2020-11-29 08:19:09
问题 I have a requirement from a client to have a search-field where he wants to input any text and search for every word in that text field in multiple full-text indexed columns which contain customer information, from a customer information table. So, for example, if he inputs FL Diana Brooks Miami 90210 , he wants all of these terms ( FL , Diana , Brooks , Miami , 90210 ) to each be searched into the State, FirstName, LastName, City and Zip columns. Now, this seems totally a bad idea to begin

Fulltext search multiple columns for multiple search terms

依然范特西╮ 提交于 2020-11-29 08:18:49
问题 I have a requirement from a client to have a search-field where he wants to input any text and search for every word in that text field in multiple full-text indexed columns which contain customer information, from a customer information table. So, for example, if he inputs FL Diana Brooks Miami 90210 , he wants all of these terms ( FL , Diana , Brooks , Miami , 90210 ) to each be searched into the State, FirstName, LastName, City and Zip columns. Now, this seems totally a bad idea to begin

Fulltext search multiple columns for multiple search terms

走远了吗. 提交于 2020-11-29 08:16:32
问题 I have a requirement from a client to have a search-field where he wants to input any text and search for every word in that text field in multiple full-text indexed columns which contain customer information, from a customer information table. So, for example, if he inputs FL Diana Brooks Miami 90210 , he wants all of these terms ( FL , Diana , Brooks , Miami , 90210 ) to each be searched into the State, FirstName, LastName, City and Zip columns. Now, this seems totally a bad idea to begin