sql-server-2012

freebcp: “Unicode data is odd byte size for column. Should be even byte size”

醉酒当歌 提交于 2019-12-08 15:17:11
问题 This file works fine (UTF-8): $ cat ok.txt 291054 Ţawī Rifā This file causes an error (UTF-8): $ cat bad.txt 291054 Ţawī Rifā‘ Here's the message: $ freebcp 'DB.dbo.table' in bad.txt ... -c Starting copy... Msg 20050, Level 4 Attempt to convert data stopped by syntax error in source field Msg 4895, Level 16, State 2 Server '...', Line 1 Unicode data is odd byte size for column 2. Should be even byte size. Msg 20018, Level 16 General SQL Server error: Check messages from the SQL Server The

All rows tagged with a specific set of values

 ̄綄美尐妖づ 提交于 2019-12-08 14:06:43
问题 To be more specific, for a many to many relation between Questions and Tags as sql server tables (including the helper table QuestionsWithTags), is needed a query/sp that returns all the questions that have the following tag set "t1", "t2" and "t3". The discriminator there is not any of the tags, but all of them, no less, no more than that. Thanks in advance. 回答1: You can solve this using aggregation and a having clause: select questionid from QuestionsWithTags qwt group by questionid having

Update every field depending on the same and other fields

眉间皱痕 提交于 2019-12-08 13:54:44
问题 I'm an ameture using SQL server 2012 and need help with an update query. I have a SQL table showing results. Every result is unique through the date of the event, the ContestID and the rank of the result (1st 2nd 3rd etc.) Every result has allocated points depending on how well they did in the event. Last place, 4th, 3rd, 2nd and 1st have the same points for each event but points between last and 4th are calculated depending on how many results there are. E.g. 7 RESULTS: OLD 1st - 150pts 2nd

Order table randomly but with exceptions

不问归期 提交于 2019-12-08 13:34:33
问题 I have a table which I need to sort randomly, but some rows need to stick together. For example, the table is generated like this All the rows which have the CATEGORY = C and CODE = 101 need to be in sequence(one after the other), but at random position in the general order. Others rows need to be randomly sorted. It's possible to do this only with "order by"? 回答1: Try this: DECLARE @exceptionOrder uniqueidentifier = NEWID() SELECT ID, Category, Code FROM yourTable ORDER BY CASE WHEN Category

new column to calculate overtime

十年热恋 提交于 2019-12-08 13:22:22
问题 I wrote and managed this query to calculate total time a person has worked per day by dateDiff function now i am stuck at one place. i want to calculate that if a person has done over time than a new column should show OVERITME in hh:mm. I n our office total working hours are 08:00 hours, greater than 8 hours are considered overtime so e.g. if a person has worked 08:35 hours than a column should show that a person has worked 00:35 QUERY: with times as ( SELECT t1.EmplID , t3.EmplName , min(t1

create type in sql server with allowed values

不羁岁月 提交于 2019-12-08 12:20:44
问题 I want to create a type in sql-server which is similar to DOMAIN in postgresql. CREATE DOMAIN degree_level NVARCHAR(10) CONSTRAINT degree_level_test CHECK (VALUES IN (’Bachelors’, ’Masters’, ’Doctorate’)) Note: I know this query is not correct. Is it possible to create such types in SQL-server? 回答1: In sql Server you will need to do this in two steps 1) Create a Type 2) Create a constraint Create A TYPE CREATE TYPE dbo.degree_level FROM NVARCHAR(10) GO Create a Constraint on Table Level

Data Manipulation Row_Number() SQL SERVER

断了今生、忘了曾经 提交于 2019-12-08 11:54:30
问题 I need some guidance and help with a data manipulation question in SQL SERVER 2012. This is how my data looks like: ================================================= YearMonth LocationCode New ValidTo ================================================= 201412 2020 1 201502 201501 2020 1 201503 201503 3030 1 201506 201506 3030 1 201509 Problem description if you look at the above table, you will see the column YearMonth , locationCode , New which tells whether the locationCode is new for the

SQL Server 2012 trigger: Execute dynamic sql for each row

爷,独闯天下 提交于 2019-12-08 11:31:54
问题 I have a trigger in a table which keeps all the changes (Insert, Update, Delete). When I insert only one row per time it works fine. But when I am trying to insert multiple rows at once I receive this error : Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. Here is the code of the trigger ( I removed some parts that are not needed to shorten the code like variable declarations etc.) UPDATE:

SQL Server 2012 make HTTP 'GET' Request from a stored procedure

对着背影说爱祢 提交于 2019-12-08 10:54:22
问题 I was given a web service that returns a JSON object. My task is to make an HTTP 'GET' request to that web service and store the JSON data retrieved to a table every 5 minutes. I am thinking about creating a stored procedure and then a job that would execute the stored procedure every 5 minutes. My question is, can you make an HTTP request from a stored procedure? Is there a better approach to accomplish this goal? 回答1: I ended up using a CLR function (using C#) to pull the JSON Object from

Transaction with loopback linked server - locking issues

久未见 提交于 2019-12-08 09:52:22
问题 I have two databases A and B . They are both stored on one database instance. I created a loopback linked server on the instance. Database A contains one table dbo.Users and one stored procedure updating dbo.Users table. In database B I have a query which does two things: Execute the stored procedure from database A which updates the dbo.Users table. Select data from dbo.Users through the linked server. BEGIN TRANSACTION EXEC [LinkedServer].A.dbo.UpdateUser select * from [LinkedServer].A.dbo