I’ve been playing around with OPENJSON in sql and have a question. Say I have the following JSON, [ { “id” : 2,”firstName”: “John”, “lastName”: “Smith&…
SQL Alias an entire query
I have a query that I am trying to assign an alias to so that I can take a primary key that I made by concatenating some of the columns together against two other queries. The code goes like the below….
Multiple ids in a unique column each and joining them to get details of each on the same line
I’m having in one table a master_id, and student_id. I want to write a query that would print out both the names of the master and student on the same line while joining their details from another table. master student table assignments table So I’m trying to write a query that would return the re…
Dynamic SQL search improvement
I have this SQL query that I am using for dynamic search in the database: In the database I have e.g.: If I provide the input Microsoft Visio I would like it to list How can I improve my SQL query to achieve this? I have done googling, but haven’t found what I want to do exactly. Answer Either pass
How to ignore the GO statements in IF EXISTS block?
I am trying to execute a script based on IF NOT EXISTS condition. But, the block within BEGIN and END gets executed even if IF NOT EXISTS returns 1. I cannot change statements within BEGIN and END blocks. How to handle this situation? Answer As I mention in the comment, GO is not a Transact-SQL operator, it&#…
how to save database versioning as a sql_last_version variable in logstash
What I’m trying to do is to save the greatest version of rows in the sql_last_value parameter as shown below in my log.conf file after each time it executes. This is my log.conf for logstash: for instance, this is my table: I’m expecting to store 600 as the last_version parameter. I’m sure i…
Filter results by user role
I have a query that returns the total number of users per a specific meta value (gender), considering only users that are not blocked (user_blocked_access): I have to return only the results for a specific user role: But don’t know where I should adds this part of code. Answer You can add an additional …
How to mirror auto increment value and combine with value in another column in mysql
I have an auto increment column id in a table, this works fine but I am trying to create an order_id column that combines the account_id of a user with the auto increment value of id. So the values inside order_id look for example like this: Where the number before the dot is the account_id and the number aft…
How to round timestamp to nearest day with postgresql
How can I round a timestamp to the nearest day in postgresql. I have tried using function date_trunc(‘day’, d_date::timestamp) but I get that is always staying in the same day. Example 1: Example 2: (This one works fine) Answer You could add 12 hours to the timestamp and then do the truncation tha…
SqlBulkCopy error: The locale id ‘0’ of the source column .. and the locale id ‘1033’ of the destination column .. do not match
I know there are similar questions but I still haven’t found the answer to this problem. My setup is the following. Source table: Destination table: SqlBulkCopy call: Working scenario: If my reader executes the query SELECT * FROM BulkTable the sqlBulkCopy works fine. Non-working scenario: this logic mu…