Newest 'sql-server' Questions

Q&A for professional and enthusiast programmers

update with subquery

The code : UPDATE tt_t_documents SET t_Doc_header_ID = (SELECT MIN(dh.Doc_header_ID) FROM tt_t_documents td WITH (NOLOCK) ...

How to get a date basis hourly count by query?

In SQL How to write a count by query based on 1 hour time duration interval for date time. I can write query based on date. But date and Time Stamp would be a Pivot structure. How to get a date ...

Recursive parentIDs

I have a table that include department data and it has the following structure, +----------+--------+----------+ | deptName | deptID | deptHier | +----------+--------+----------+ | a | ...

TSQL - Creating a consolidated schedule from contiguous schedule parts

I am having the absolute worst time trying to consolidate a list of schedule parts into a more concise list when start and end times match. The code below is for a single schedule, and the code is a ...

SQL real estate agend column

I am making a real estate agency database. The tables that are currently included in the question are a table for the employees, purchases and the real estates. I want to put a ServedByEmployee column ...

How to hide duplicate values from rows in sql

I am trying to export table data to excel format. My present view's select query give result like this .. IDs Column_A Column_B Column_C Column_D Column_E 1 EDC RFV TGB ...

SQL price column confusion

I am currently making a real estate agency database. With a few words... the database has a table for the purchases and for the real estates... (it actually has more but I think they are not necessary ...

SQL - Case When on same row

I have a problem with a query that involves multiple case whens SELECT DISTINCT ,-1*(SUM(ISNULL(DB.[Commission_Bal],0)) + SUM(ISNULL(UP.AMOUNT,0))) AS [Commission_Bal] ,...

Why do i need to have create database permissions for asp.net web app?

I am building an ASP.NET, code-first web app. I am using a company owned database, and have crud permissions for tables within one database on this server. I do not believe I have "Create Database" ...

return the first row of value when a column has the same value 4 times consecutively

Thanks for the help in advance. I'm working in MS SQL Server 2008 and trying to capture data from the first row with a value of "0" in the Auto_Manual column, where there are at least four "0"s in a ...

Get Data and Map to Controls from Combobox Selected Value C#

I am trying to get required data into controls when i select specific Student Name from a combobox. i am using SelectedValueChanged event for this and the valuemember for that combobox in order to ...

Large query as variable not evaluting in dataflow expression builder SSIS

I am querying a Cache database through an ADO net datasouce in my dataflow in SSIS (SQL 2008 R2). I want to pass parameters to the query but can only do this through the expressions section of the ...

CAST or TO_TIMESTAMP function in Oracle from SQL?

I have a SQL query that was written for a SQL Server table and would like to translate/convert it to an Oracle query. How should this query be written to use CAST or TO_TIMESTAMP instead of CONVERT? ...

SQL Server query; last record for each ID

i'm looking for a query, which gives me for each ID the last record (based on date, which is given, and timestamp). In my case, the ID is "knr", so i want the last record of every KNR in event_ap (...

How To Call a Stored Procedure with an Output using C#

I have this SQL Server stored procedure that provides an output value. Note the output value is the identity seed that gets created when the new record is added. @EventNumber varchar(12), @...

Could not load file or assembly Microsoft.SqlServer.PipelineHost

I am using Visual studio 2015, with the deployment target version of SQL Server 2016. It works on my local machine but when I transfer the files over to the server and run the package. It errors with: ...

SQL DateTime Overflow Using Multiple LINQ Statements

I have the following issue. In the below code block the first time through an if statement fires off and everything goes fine. The second time through the formData.Where errors out with an SQL ...

SQL Server - How to Use Merge Statement for Slowly Changing Dimension with More Than Two Conditions?

I am trying to implement Slowly Changing Dimension Type 2 through T-SQL but I can't figure out how to put a request to work. Table columns: cpf, nome, telefone_update, endereco_insert Basically the ...

Asp.Net MVC 5 Project on IIS, Login failed DOMAIN\MACHINE$ for Sql

I am developing a website with the Asp.net MVC5 template. This website have obviously a database with some informations. This MS-Sql database runs on a remote VM. While coding I tested this site with ...

sql server RESTFULL API for AJAX [on hold]

Does anyone know how to build a RESTFUL API to usewith existing sql server database? I'm using AJAX/Javascript/Jquery/Apache Cordova. Thank you!

Remove records by clustered or non-clustered index

I have a table (lets say ErrorLog) CREATE TABLE [dbo].[ErrorLog]( [Id] [int] IDENTITY(1,1) NOT NULL, [Created] [datetime] NOT NULL, [Message] [varchar](max) NOT NULL, CONSTRAINT [...

Complex join quick by itself, slow as a join

I'm trying to help a coworker with a large complex query. One of the joins returns the data correctly but performs poorly. If we run the join by itself, it returns in seconds. As part of the larger ...

Spring Data + JPA > New entries of “mappedBy” property are not fetched from DB after SQL INSERT

Hej. I think I am experiencing some odd behaviour with Spring Data, JPA and the alike. I wrote a flyway migration script that inserts new data into a table cash_entry_note. Which is related to an ...

SQL conditional logic on one field not affecting the grouping

I have the following data: ID ActionType Quantity Fee 1 Commission 1 10 1 Open 2 10 2 Commission 1 20 2 Close 3 20 3 Commission 1 ...

combining comparisons operators

Please advise how to change the following code to extract also records with [execution_status] like 'failure' and at the same time [has_messages] like '0'. I'm trying different ways and all the time ...

Using TDE by upgrade SQL server 2012 standard to enterprise edition

Can we upgrade SQL server 2012 standard edition to enterprise edition to "enable" TDE by using wizard? Anyone has experience can share with us? Thanks!

How can I issue a LINQ query to a SQL Server to check if a column value starts with a word?

I have this already if (options.English != null) query = query .Where(w => w.English.Contains(options.English)); What I would like to do is to extend this (maybe with another ...

Alternate for updating record

I have temporary table in which ,i have set a column as FLAG with value '0'. I am using a cursor in stored procedure,where in the column named FLAG gets updated as '1'as loop executes for 3 three ...

Find dependencies for particular column across multiple databases

I'm looking to find references to a particular column throughout all of my databases. the script below checks to see if the column exists in other tables across databases but I want to go further to ...

Error when inserting large amount of rows to a table with rowversion/timestamp column (SQL Server 2016)

I'm trying to insert large amount of rows with an INSERT INTO / SELECT statement to a table that has a rowversion/timestamp column. The INSERT statement always returns an error: An internal error ...

is this correct? where i am trying to get multiple columns from 3 tables using alias name for each column using union

Is this correct? where I am trying to get multiple columns from 3 tables using Alias name for each column using union. SELECT pid AS id, product AS [product], type AS [type], ...

SQL Update to Linked Server Table fires trigger for each row effected

I'm looking at some strange behaviour with a linked database server. I'm simply creating a temporary table variable, adding in some keys which can be found in the linked server table and using it to ...

Joining two tables with special case on the right table?

I have two tables: Candidate: {Id, Name} and Candidate_Education: {Id, CandidateId, Education, GraduationDate} I want to show the candidate name and his last education , I made that query: SELECT c....

How can I remove duplicates from my file, while certain fields take priority?

So I have SQL that will add a code to a field if it detects duplicates. There is another field called DS DS can either be 'yes' or it can be 'no' How can I make it so if it finds a duplicate, 'yes' ...

SQL Thesaurus searches

I have made a custom thesaurus file with entries as follows <expansion> <sub>RGN</sub> <sub>Registered General Nurse</sub> </expansion> The problem I am ...

Part of SQL query is deleted when saving a View

I have an SQL View I am adding these two lines : AND (NOT((Segment = 7) AND (Type= 'Reserved'))) AND (NOT((Segment>= 6) AND (Type= 'NotReserved'))) The query works, but when I save the View, NOT((...

Left Join Entity Framework not running

I'm trying to make a "LEFT JOIN". However, only when I have information "in both tables" does the command return something. Bellow my function public IList<ClientWorkFlowReadModel> ...

How to divide the input of a variable when reach it's maximum length

I am writing a procedure which takes the body of other procedures and store them localy in my device as a text file It works fine but i notice that if am having a large procedure it will be cut off ...

SQL Dynamic Pivot Table [duplicate]

I'm struggling with an error while making a dynamic pivot table The source data is JobID | SalesForMonth | YearMonth 7734 | 400 | 2016-12 7734 | 350 | 2017-01 8540 | 444 ...

Dynamically add columns to temp table based on rows in another temp table

I am trying to build a temp table with a dynamic number of columns based on the number of rows from another temp table. Say I have 89 rows in #table1, in #table2 I would like to use the row count and ...

MSSQL & SQL data type alternatives?

I have to work on a project connecting to a SQL Server DB, while working with PHP and a Laravel framework. My issue is with the data types and where I would be able to change them into fully ...

Export Images from Database to local folder

I have two columns in a table: ID, Image (Bytes) I need to storage all the images in a local folder using the ID as a Image name. How can I do that?. I musing SSMS 2008 R2.

VS2015 DB project Schema Compare partial update

I have a pre-existing database with hundreds of tables and procs. A few of the tables have triggers also defined. When I create a brand new project and run a schema compare, all of the items show up (...

SQL Update & INNER JOIN

I'm trying to update a specific column in my DB (Using MSSQL) I have wrote a query to return the values already, but the problem I can't update the other table with the generated values from (More ...

Running Powershell via SQL Server Job

I have a very basic script which runs fine on my local PC. It simply backs up some folders and their contents then adds a date stamp on the folder name. The script backs up folders on two different ...

SQL server duplicates retaining the latest

Could you please help with a cte to fetch the duplicate records on the below data set and make them inactive, latest date record should remain active? if Fname, Lname and email are same -duplicate if ...

MSSQL ODBC refusing valid TINYINT values (Numeric value out of range)

I'm trying to insert into a TINYINT column which according to MSDN docs should take numbers between 0-255. Unfortunately it only takes 0-127. If I try to insert 128 or higher it complains: [22003] (...

SQL Server Linux Docker image keeps exiting

Setup Windows 10 Pro Docker for Windows 1.13.0-beta38 (9805) Dockerfile FROM microsoft/mssql-server-linux:latest ENV ACCEPT_EULA "Y" ENV SA_PASSWORD "my_strong_Password!" EXPOSE 1433 Issue ...

Why Undefined index query and index: check? [duplicate]

I am getting the following error on a PHP: Notice: Undefined index: query Notice: Undefined index: check $sql = $_POST["query"]; $sql = urldecode($sql); $result = sqlsrv_query($...

How can I update a column in a table where all the values of another column start with “to ”?

I would like to do an update but limit it. How can I update the table phrase and set the field politeness to the value of 1 for all rows where the column english starts with "to ". Note there is a ...
Translating... 0%