sql-server-2012

Avg of float inconsistency

你离开我真会死。 提交于 2019-12-28 03:12:05
问题 The select returns right at 23,000 rows The except will return between 60 to 200 rows (and not the same rows) The except should return 0 as it is select a except select a PK: [docSVenum1].[enumID], [docSVenum1].[valueID], [FTSindexWordOnce].[wordID] [tf] is a float and and I get float is not exact But I naively thought avg(float) would be repeatable Avg(float) does appear to be repeatable What is the solution? TF is between 0 and 1 and I only need like 5 significant digits I just need avg(TF)

Subquery v/s inner join in sql server

杀马特。学长 韩版系。学妹 提交于 2019-12-28 02:03:05
问题 I have following queries First one using inner join SELECT item_ID,item_Code,item_Name FROM [Pharmacy].[tblitemHdr] I INNER JOIN EMR.tblFavourites F ON I.item_ID=F.itemID WHERE F.doctorID = @doctorId AND F.favType = 'I' second one using sub query like SELECT item_ID,item_Code,item_Name from [Pharmacy].[tblitemHdr] WHERE item_ID IN (SELECT itemID FROM EMR.tblFavourites WHERE doctorID = @doctorId AND favType = 'I' ) In this item table [Pharmacy].[tblitemHdr] Contains 15 columns and 2000 records

How to select specific data between Quotes (")

孤者浪人 提交于 2019-12-25 18:54:09
问题 I am reposting my question as I am new to SQL 2012. I want to fetch the numeric data between quotes (") in the following rows, row1:'asdalknd," 1,2,3,4 ",slknsdl," 5,6,7,8 ",snlsn' row2:'asknd," 111,267,387,4756 ",snsdl," 534,646,767,348 ",snlssdsdsdsjkvkn' row3'.... row4'.... row5'.... row6'... row7'... row8'.... The above mentioned are the rows of a single column. I just want to extract the numerics(may be in another column for each rows) Can anybody pls help, as this is way above my basic

Is there any way i can just create a table in SQL Server and then update the migration to my project?

瘦欲@ 提交于 2019-12-25 18:38:32
问题 I have imported database tables from MS SQL Server 2012 and migrated them to Visual Studio 2015 using code-first concept shown in this example. Its working but just now i just added a new table in SQL Server and i wanted to update the DBContext in my project with the new table. I tried entering "add-migration new_table_name" in the Package Manager Console but it didn't work. I understand that i have to code a new model manually in the Models folder of my project, then only that migration will

Stored procedure throws error in SQL Server 2012 but works fine in SQL Server 2000

与世无争的帅哥 提交于 2019-12-25 18:11:29
问题 I have a stored procedure that works fine in SQL Server 2000 but throws an error on SQL Server 2012 Express where we are moving the DB to. [SQLServer JDBC Driver][SQLServer]The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns. Anybody able to help me sorting this out? CREATE PROCEDURE spSelectTopCourses AS declare @divisor int declare @column int set @column = 6 -- number of columns in the site

Split a single row into multiple rows using SQL

£可爱£侵袭症+ 提交于 2019-12-25 18:10:03
问题 I am trying to generate multiple rows from a single row and was able to do it using the below SQL. But I am wondering if there is a better way to write this SQL as its very long and can't apply to real-time scenarios. Thank you. Note:- My query would return the desired output but it is not an efficient way to solve the problem. My actual input has more columns and I don't want to write 'n' no. of SQL queries and do a UNION ALL for all of them. Please suggest a better solution. Thank you.

Split a single row into multiple rows using SQL

别等时光非礼了梦想. 提交于 2019-12-25 18:09:13
问题 I am trying to generate multiple rows from a single row and was able to do it using the below SQL. But I am wondering if there is a better way to write this SQL as its very long and can't apply to real-time scenarios. Thank you. Note:- My query would return the desired output but it is not an efficient way to solve the problem. My actual input has more columns and I don't want to write 'n' no. of SQL queries and do a UNION ALL for all of them. Please suggest a better solution. Thank you.

TSQL Maxrecursion on a cte

瘦欲@ 提交于 2019-12-25 12:01:39
问题 I get this error: The maximum recursion 100 has been exhausted before statement completion when I run this function: WITH allDays AS ( SELECT @DateEarly AS date UNION ALL SELECT DATEADD(dd, 1, date) as date FROM allDays s WHERE DATEADD(dd, 1, date) <= @DateLate ) SELECT * from allDays where dbo.isFestivo(date)>0 I tried to append this option: OPTION (MAXRECURSION 200); but i get an error 156 before "option" word. Do you know why? 回答1: You're probably putting the option in the wrong place. It

Statistics on large table presented on the web

末鹿安然 提交于 2019-12-25 11:57:15
问题 We have a large table of data with about 30 000 0000 rows and growing each day currently at 100 000 rows a day and that number will increase over time. Today we generate different reports directly from the database (MS-SQL 2012) and do a lot of calculations. The problem is that this takes time. We have indexes and so on but people today want blazingly fast reports. We also want to be able to change timeperiods, different ways to look at the data and so on. We only need to look at data that is

SQL statements to ROLLBACK but Audit inserts to COMMIT

故事扮演 提交于 2019-12-25 09:25:53
问题 SQL Server 2012 I have a Master stored proc, which calls several other 'child' stored procs. The master proc encapsulates the child procs in a transaction. Throughout the master and child procs, there are many inserts into an audit table. If the process succeeds, I get a detaied chain of events. If the process fails and rolls back, I would like to have a record of the last child proc processed in the Audit table, but the whole thing is rolled back, including the audit data. Is there a way to