Tag: sql

SQL Data Conversion Failed DateTime

This question already has an answer here: Conversion failed when converting date and/or time from character string while inserting datetime 9 answers

String or binary data would be truncated – large strings

We have an extremely large nvarchar(max) field that contains html. Within this html is an img tag. Example: <img style=”float:right” src=”data:image/png;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/7gAOQW…. The length of this column is 1645151, although what is being replace is a bit less than this, but not a lot. What we are trying to do, is a replace in SQL on […]

SQL timeout on specific select query

I have a SQL query like the one below. The database tables are not indexed and unfortunately I cannot do anything about it. In the application using this query I have experienced sporadic SQL timeouts. When such a timeout was happening I used LinqPad to execute the exact same query with the same parameters and […]

converting mysql sql to sql server

I have a MySQL SQL that works fine with Jaspersoft report: SELECT pr.id AS project_id, pr.project_name as project_name, pr.export_event_id, au.full_name, ee.timestamp FROM ( SELECT project.id, project.project_name, MAX(project.export_event_id) AS max_export_event_id FROM project INNER JOIN export_event iee ON project.export_event_id = iee.id where IIF ($P{exportEventDate} IS NULL, TRUE, CONVERT(DATE, iee.timestamp) <= $P{exportEventDate}) GROUP BY project_name ) AS in_PR […]

SQL Not returning the same as it does when embedded in a SSRS Report

I am hoping someone can help me? I have been tasked with updating a report but for some reason when I try to run the SQL emabedded in the SSRS Report it does not return any results. But it works fine within the report. I am passing in the exact same params so is a […]

Not getting actual minutes in SQL DateDiff

I searched in different places and found below queries. I am using the following queries to get the actual minutes difference in SQL. The dates I provide are the same day. I need difference in minutes only but SQL is returning 35 instead of 5 minutes in the first query. And the second query return […]

T-SQL Finding Missing item from another database

I have 2 databases for 2 different system. EDI system and ERP System as below I would like to know all the ProductId that are not in ErpOrderItem table for all the orders in EDI System Order table A. EDI System Order —- 1. OrderId 2. OrderDate OrderItems ——— 1. OrderItemId 2. OrderId 3. ProductId […]

How to pass string parameter with IN during in pivot table using SQL server

I have tried with this code to get my result, but I can not understand what I have missed. I have below table(s) and try to generate a dynamic sql to get the result. Declare @date1 date = ‘2015-06-01’, @date2 date = ‘2015-06-30’, @StoreNo Nvarchar(Max) = ‘ AND S.StoreNo IN (61,63,450,451)’ AS BEGIN Declare @sql_store […]

simple Merge delete failing

FirstTable ColumnOne | TabletwoCol | TablethreeColumn | 1 | 2 | 5 | 2 | 3 | 6 | 3 | 8 | 10 | SecondeTable (TableTwo) TabletwoCol | Coln | 2 | ABC | 3 | lmn | 8 | as | 1515 | addd | I want use Merge delete to delete from […]

Trying to use CASE statement in SQL Server

I have table with the data as shown below, create table #UserRegion ( UserName varchar(25), RegionName varchar(25), RegionID varchar(10), RegionStatus varchar(15), DefaultFlag char(1) ) Insert into #UserRegion values (‘UserOne’, ‘Chicago’, ‘MW-1’, ‘Oniline’, ‘1’), (‘UserTwo’, ‘SanJose’, ‘W-6’, ‘Oniline’, ‘0’), (‘UserThree’, NULL, NULL, ‘Oniline’, NULL), (‘UserFour’, NULL, NULL, ‘Oniline’, NULL), (‘UserFive’, ‘Miami’, ‘E-4’, ‘Oniline’, ‘0’) I want […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.