SQL - Why Does This Happen?

These are the tables that I'm working with. With that in mind, I want to showcase the Employees that are both a supervisor and a manager. But when I used this select e1.fname,e1.lname from employee e1,employee e2,department where e1.ssn=e2.super_...
more »

2017-03-19 17:03 (2) Answers

Pivot in SQL Server with where clause

I am in need for using Pivot in SQL for getting the rows converted in columns, but not able to do so with my pivot query. create table TestTable ( id int, colVal int ) insert into TestTable values(1,1) insert into TestTable ...
more »

2017-03-19 15:03 (1) Answers

Query json data using Splunk

We have compressed data in json format at azure storage (tables and blobs) I want to ETL the data to relational DB in order to have the option to run sql queries on the data I have an utility which decompresses the data to json files, I did it via S...
more »

2017-03-19 14:03 (0) Answers

SQL Order by the sum of aliases

To preface, this is Microsoft SQL Server. I have several different columns of various earnings from different years. I need to order by the total sales of each given product, but not report it as an actual column. The commented line is how I tried...
more »

2017-03-19 08:03 (4) Answers

SQL join return rows when Where not satisfied

I have a table of Monkeys and a table of Trees with a many-to-many relationship joined by a third MonkeysTrees FK Table. I have this query that returns all the Monkeys and Trees for a given Tree Id: SELECT * FROM Monkeys m JOIN MonkeysTrees mt ON ...
more »

2017-03-18 22:03 (1) Answers

Results from query values in one column

I am just curios about something I've never come across in sql server before. This query: SELECT N FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) T(N) gives me result: +---+ | N | +---+ | 0 | | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 |...
more »

2017-03-18 14:03 (2) Answers

SQL - full outer join

i have three table in sql database i need to join this three table to get table like this I want to join three table to get all data from whole first, third and second (where sort is 2) table I try this query select table1.Item, table1.L...
more »

2017-03-18 12:03 (4) Answers

sp_send_dbmail embed mhtml file in body

I have an SSRS report that I need to embed in the body of an email using the sp_dbmail stored proc in SQL Server. I'm able to do this using the front end of Outlook by attaching the .mhtml export of the SSRS report using the "Insert as Text" option w...
more »

2017-03-17 22:03 (2) Answers

Determine days of week from bit mask

I am working with a third party application and am trying to extract meaningful information about shift information based on the data. shift_pattern_start_dt pattern 2014-05-27 1111000 2015-10-25 1110011 2014-05...
more »

2017-03-17 19:03 (1) Answers

SQL server script for generating script for table

I have following situation: I'm working on project where data base contains hundreds of tables, and very often I know what table I need to generate script for, but finding it in the list of all tables takes a lot of time. I would like to know, is the...
more »

2017-03-17 17:03 (2) Answers

Exception out of memory from Android

I have a problem with restoring Images from the database to the android using a type byte [] and we pass ArrayList images to our adapter in which we use Glide, but I can recover more than 20 images of the database using service web PHP , applicatio...
more »

2017-03-17 10:03 (1) Answers

Puzzle: Spreading numbers evenly in groups

This is more of a puzzle really. Its probably been asked elsewhere before, but I couldn't find anything so I thought I'd share the question. I'm trying to implement some kind of load balancing in an application and have reduced the problem down to ...
more »

2017-03-16 17:03 (5) Answers

Concatenate with FOR XML changes encoding

I have a query which converts a number into a set of ASCII characters and then attempts to concatenate them into a string: declare @number int = 651854564 ;with cte as ( select @number prev_nr , cast(char(@number % 256) as nvarchar(100)) nextch...
more »

2017-03-16 16:03 (2) Answers

SQL Server Ranking issue

I am trying to apply ranking to my data set the logic is as follows: For each ID , Order by ID2 ASC and Order by IsMaster Desc rank the row 1 and only change it when the ID4 value changes My dataset and desired output looks like: Test data CR...
more »

2017-03-15 14:03 (4) Answers