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

using count query in sql

How could I write an SQL that will display authors and a total number of their publications with a sub query included in my SELECT STATEMENT but this is what I have ...
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

Yaml to database

For my c++ program, I use jobs.yml which contains information about jobs in yaml format like: 141647523: JobType: Turbo LocalJobID: 16773779.0 Status: Done SystemPriority: 0.0 UserPriority: 8.0 Then I use yaml-cpp library for parsing fil...
more »

2017-03-17 15: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

Specify my own execution plan for query

Lets say I know a lot about the distribution of my data, and therefore know the optimal execution plan for a query. Is there a way to specify my own execution plan, fully circumventing table statistics and the optimizer? ...
more »

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

SQL Server ISNUMERIC returning wrong data

I am using SQL Server 2008 R2. When I execute the following query, ISNUMERIC is evaluating to true(1) when the barcode clearly has 'D' inside it. SELECT ISNUMERIC('7210300106D30') If I execute the same code with other letter than D or E, it seems...
more »

2017-03-14 14:03 (5) Answers

Converting GETDATE() to Hijri date to yyyymmdd

I am trying to get the Hijri GETDATE() and convert it into this format yyyymmdd I have already tried this script SELECT CONVERT(VARCHAR(10), GETDATE(), 131) but it gives me this format ( 16/06/1438 ) and what I actually need is (1438/06/16) ...
more »

2017-03-14 13:03 (6) Answers

Adding two count(*) results together

I have these two queries and I want to add them SELECT count(*) FROM table2 GROUP BY table1_id SELECT count(*) FROM table3 GROUP BY table1_id I tried something similar to the accepted answer in this question. The difference is that I have a group ...
more »

2017-03-13 20:03 (3) Answers

Double loop with drop table in MSSQL

I've while loop inside while loop and both loops do some modifications of one table. I receive an error that table already exists. Below simple example of this problem. Could someone clarify why this doesn't work? I know how to bypass this problem in...
more »

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

Rails .where() query not working

Thanks a lot for your help. I have a locations and ads table. Location has_many :ads I perform the following query on Location Model. @locations = Location.joins(:ads).where(@location_params.require(:location).permit(:id)).includes(:ads) Then I wa...
more »

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

Need help understanding AUTOINCREMENT from SQLite

I'm learning SQLite from this webiste: SQLite Tutorial. I was reading the article they had on the AUTOINCREMENT command. My question had to do with their explanation of why this feature is useful: The main purpose of using AUTOINCREMENT attribu...
more »

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

Need assistance with this SQL query

This is an example of my table. I have multiple entries on multiple rows for a given post_id (this is metadata for posts). post_id | meta_key | meta_value ________ __________ ___________ | | 1 | _theDate | 2016-03-31 1 ...
more »

2017-03-12 21:03 (5) Answers