sql-server-2012

DATE_FORMAT error in ruby in rails 4 with sql server 2014 as a database on windows 7

蓝咒 提交于 2019-12-12 04:58:34
问题 i am getting DATE_FORMAT error in ruby on rails with sql server as a database <% date = Date.today %> <% @employees = Employee.where("status = ? AND DATE_FORMAT(date_of_birth,'%d/%m') = ?", "Active" , date.strftime('%d/%m')) %> 回答1: Try this, <% date = Date.today %> <% @employees = Employee.where("status = ? AND FORMAT(date_of_birth,'dd/MM','en-US') = ?", "Active" , date.strftime('%d/%m')) %> Learn more about Format function 来源: https://stackoverflow.com/questions/43270910/date-format-error

Using a CTE to split results across a CROSS APPLY

≡放荡痞女 提交于 2019-12-12 04:47:59
问题 I have some data that I need to output as rows containing markup tags, which I'm doing inside a table valued function. This has been working fine up to a point using code in the format below, using the search query to gather my data, and then inserting into my returned table using the output from results . I now need to take a longer data field and split it up over a number of rows, and I'm at something of a loss as to how to achieve this. I started with the idea that I wanted to use a CTE to

I need to create a view that unions all tables based on their prefix (new tables added monthly)

▼魔方 西西 提交于 2019-12-12 04:43:10
问题 The integration software that my client is using is pulling over ISAM files from a RMS system and creating lots of tables that all have identical schemas, but nonetheless the software they use doesn't support merging them together. Here's some example table names: SOME_TABLE_XYZ_2012OCT SOME_TABLE_ABC_2012OCT SOME_TABLE_LMN_2012OCT SOME_TABLE_XYZ_2012NOV SOME_TABLE_ABC_2012NOV SOME_TABLE_LMN_2012NOV I need to roll these all up into a single view named SOME_TABLE, with the data union all'd

How can we do pagination in fetching the value with 100 records each in sql

拟墨画扇 提交于 2019-12-12 04:26:07
问题 How can we do fetching first 100 records next 100 records then next and so on in SQl Server from a table 回答1: Use CTE and OFFSET : @RecordIndex=Start Row No @PageSize=No of Rows to fetch ;WITH CTE_Results AS ( SELECT ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS ROWNUM, Count(*) over () AS TotalCount, * FROM TableName ) Select * from CTE_Results ORDER BY ROWNUM OFFSET (@RecordIndex) ROWS FETCH NEXT @PageSize ROWS ONLY; 回答2: Here is the procedure that will give you pagination based on the

Trigger compare inserted to deleted data issue

不打扰是莪最后的温柔 提交于 2019-12-12 04:14:27
问题 I have faced below issue last time and just wondering why null <> 'value' doesn't work in trigger. To resolve issue I had to use isnull function isnull(null,'') <> isnull('value','') All code to test below: -- create main table CREATE TABLE T_SAMPLE ( ID INT, NAME NVARCHAR(20) ) GO -- populate data in main table INSERT INTO T_SAMPLE VALUES (1, 'ONE'), (2,'TWO'), (3,'THREE') GO -- create table to store changes CREATE TABLE T_SMAPLE_TEST ( NAME NVARCHAR(40) ) GO -- create trigger on main table

How to find consecutive data in SQL

帅比萌擦擦* 提交于 2019-12-12 04:04:20
问题 I have the following data in a SQL Table: I want to find 3 Consecutive data by No and group with ID. Result are How to write query.please help. 回答1: Here is query which select only rows where actually 3 consecutive rows are: SELECT a.* FROM TABLE as a inner join TABLE as b on (a.no+1=b.no and a.id=b.id) inner join TABLE as c on (a.no+2=c.no and a.id=c.id) order by a.id, a.no for your data it will provide: 4 a1 4 5 a1 3 1 a2 2 2 a2 4 3 a3 2 4 a3 3 rows (6,a1,1), (3,a2,5) and (5,a3,4) are not

Setting a foreign key to more than one table

浪子不回头ぞ 提交于 2019-12-12 03:55:32
问题 I have three tables Teachers, Student, ViewType table Teachers{ Id uniqueidentifier, Name nvarchar } table Student{ Id uniqueidentifier, Name nvarchar } table ViewType{ Id uniqueidentifier, Type String } Note: Let's say for the example that ViewType is not a regular look up table. it contains data of how to present the Teacher or Student in the ui therefor shouldn't be in the Teacher or Studenttable model. Is there a way to create a foreign key to two tables where a key is enforced to from

Create copy of database in sql server 2012 express

 ̄綄美尐妖づ 提交于 2019-12-12 03:41:04
问题 Hello I have database on which user work. I want to create copy of this database for testing purpose. Can anyone tell how can this be done? I tried everything from copy a database within SQL Server Express? But Copying files and attaching it destroys first database and trying to restore backup into new database throws error that database is not the same. Can anyone suggest me solution? as @Nadeem_MK suggested I created backup and now I'm trying to restore with this script: RESTORE DATABASE

Tempdb Full When Querying Distinct Count Of All Tables

浪尽此生 提交于 2019-12-12 03:38:53
问题 ORIGINAL PROBLEM I have created a custom script to retrieve data from a remote SQL server into our local copy in our office. I had some issues with the script where selected tables had some data inserted twice, thus creating duplicates. I know that for all the tables in all databases there should be no duplicates. This issue has made me paranoid that other tables may have had this problem historically, and therefore I'd like to verify this. SOLUTION I have created a SQL script to insert the

Bug in Ms SQL 2012? TVF giving unexpected result in a outer apply

ぃ、小莉子 提交于 2019-12-12 03:32:57
问题 I'm no expert in Ms SQL, but I came across some really strange behavior in Microsoft SQL Server. I am quite sure it's a bug - but wanted to bring it to more experienced eyes before I conclude that it is. (And I'm not sure how I would go about reporting it to Microsoft if it is). Environment @@Version => Microsoft SQL Server 2012 - 11.0.5343.0 (X64) May 4 2015 19:11:32 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) Step 1: