sql-server-2012

SELECT rows that have specified values in one of the columns

≯℡__Kan透↙ 提交于 2019-12-08 08:17:45
问题 I have the following table on my SQL Server 2012 : ID Name Status Address Phone 1 Tom I U D 2 Joe D U D 3 Pam D I U 4 Ken U U U How do I select the rows with ' I ' in one of the columns? for example, I expect the query to return 1st and 3rd row from the table. I know the query below works however I need a query that does not specify the column names as I need to deal with a table with more than 20 columns. SELECT * FROM table WHERE (Status = 'I' or Address = 'I' or Phone = 'I') 回答1: One way

Using Import wizard to import Excel data into table in SQL Server 2012 failing - text truncation

橙三吉。 提交于 2019-12-08 08:14:59
问题 I have an Excel file that I import weekly into a table. I am using Excel 2010 and SSMS 2012. The import failed this week and I have been unable to determine why. I was able to successfully import the data into a new table. The table definitions of the new table match the ones of my old table, so that does not seem to be the issue. Below is a screen shot of the error I receive. I have checked the PO header text field and there is nothing that exceeds the datatype of varchar(255) that I have it

Open SQL Server 2012 From Command Prompt

情到浓时终转凉″ 提交于 2019-12-08 07:56:37
问题 I have installed SQL Server 2012, SQL Server 2008 R2 and SQL Server 2014. Now when I run SSMS it always opens SQL Server 2008. What to do same for SQL Server 2012? Any shortcut key or command to run from command prompt like SSMS ? Please guide me. 回答1: I found the solution. It is so simple. Just create desktop short cut and copy that file to C:\Windows\ For example: Create short cut named as on desktop SQL Server Management Studio Now simply copy it to your C:\Windows path and rename it to

Weekly to Monthly Reports

妖精的绣舞 提交于 2019-12-08 07:52:02
问题 I was running weekly reports as in the below script. However, I now want to run monthly report so needed some assistance. Weekly: SELECT * FROM TABLE WHERE (ARRIVAL_DATE>GETDATE()-7)//7 days before AND (ARRIVAL_DATE<GETDATE()) //NOW For monthly report, will below script be right if I run on every 1st? SELECT Column1,... FROM TableName WHERE MONTH(DateColumn) = MONTH(dateadd(dd, -1, GetDate())) AND YEAR(DateColumn) = YEAR(dateadd(dd, -1, GetDate())) Thanks. 回答1: Your logic looks okay, although

Can not execute SQL Server stored procedure

元气小坏坏 提交于 2019-12-08 07:42:56
问题 I have the following procedure into which I pass a string parameter, for example ,2,3, . The procedure should return a set of rows where CategoryId is equal to 2 or 3 : CREATE PROCEDURE [dbo].[GetItemListProcedure] (@CategoriesIdString VARCHAR(1000)) AS SET NOCOUNT ON; DECLARE @SQLQuery NVARCHAR(MAX); SET @SQLQuery = N'SELECT Item.Id, Item.ModelId, Item.ItemCode, Item.CategoryId, (SELECT TOP (1) Category.CategoryName FROM Category WHERE Category.Id = Item.CategoryId) AS CategoryName FROM Item

How to escape one or more consecutive rows from table, inoutMode either 1 or 0

拟墨画扇 提交于 2019-12-08 07:39:31
问题 I have a table My table with result like as below: Id EmpCode CheckInCheckOutDate WorkDate InOutMode 85223 175 2017-10-27 11:20:39.000 2017-10-27 11:20:39.000 0 85832 175 2017-10-27 14:21:21.000 2017-10-27 14:21:21.000 1 85844 175 2017-10-27 14:36:23.000 2017-10-27 14:36:23.000 0 85863 175 2017-10-27 15:21:27.000 2017-10-27 15:21:27.000 1 85878 175 2017-10-27 16:03:46.000 2017-10-27 16:03:46.000 0 86031 175 2017-10-27 18:14:41.000 2017-10-27 18:14:41.000 1 86038 175 2017-10-27 18:34:45.000

SQL Server 2012 CHECK constraint not firing on UPDATE or DELETE statements

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 07:06:40
问题 I'm trying to perform data validation on a table, and I need to check across multiple rows and columns. Basically I want to make sure that for any given tool, at least one version exists that is flagged as either the Active version, or the Beta version. The only way I could think to check this is through a user-defined scalar function, and a CHECK constraint that calls the function. I was able to create the function that returns what I expect (0 if OK, 1 if not) and it works... but only on an

Format SQL Server 2012 Time(7) to “HH:mm”

依然范特西╮ 提交于 2019-12-08 06:36:13
问题 I have Time(7) columns for each day in the week and I want to format it as HH:mm I tried to use SQL Server 2012 new FORMAT function, but it only shows the NULL value. How can I format a time(7) datatype to display as HH:mm ? 回答1: You should always format your data in the presentation layer. If there are circumstance where the TIME datatype cannot be formatted by your UI, you can cast the value to a DATETIME which will more than likely be supported. SELECT CAST(TimeColumn AS DATETIME) FROM

Issue connecting Oracle 11g to SQL Server 2012 — ORA-12523: TNS:listener could not find instance appropriate for the client connection

戏子无情 提交于 2019-12-08 05:52:35
问题 I have Oracle 11g and SQL Server 2012 installed on the same virtual machine. OS is Windows Server 2012. I want to access SQL Server 2012 from Oracle. I created the machine a few days back to test the connection process before applying it on server. I had come through several issues but now I am stuck with this one. ORA-12523: TNS:listener could not find instance appropriate for the client connection I have already created ODBC Connection by the name of sqldb . kshaz is my machine name.

CONVERT issue in sqlserver with Msg 529 error

余生长醉 提交于 2019-12-08 05:43:30
问题 select CONVERT(datetime,value,103) from results This statement is giving me a error "Msg 529, Level 16, State 2, Line 1 Explicit conversion from data type text to datetime is not allowed." VALUE column Datatype is TEXT in the RESULTS table. How can i overcome the above problem. please help ! 回答1: You can't convert from text to datetime You must apply two convert operations. The first: From text to varchar The second: From varchar to datetime So your query will become: SELECT CONVERT(datetime,