I would like to output the result of the dynamic SQL into a variable called @Count but not sure what the syntax or even the code should like to accomplish this. The code looks as follows: thank you Answer You can utilize sp_executesql to execute your count() query, and output it @Count. Try this: One last thi…
Tag: sql-server
To UNION or Not to UNION
I am currently running into an issue with my UNION clause. I am trying to figure out how many orders I am import via each day. The problem is, I have two tables that these orders are stored in OLDORDERHEADER and ORDERHEADER. After an order is completed, it moves from the ORDERHEADER table into the OLD. Both h…
no local server type “database engine” were found (V 2016)
I don’t know many things about SQL server, today I install the SQL Server Management Studio 2016 and want to create a local Database. after search in the internet find this link from microsoft. in step 4 of this tutorial found this error when want to regester local servers no local server type “da…
create fiscal week number
How can I put the below logic into a format SQL Server will use to create a fiscal week number ? Answer The CASE Statement should work:
SQL BACKUP and Restore Full backup
I have two full backups of different dates first full backup is of date lets suppose 21-05-2017 and I have restored that backup to client machine (RESTORE WITH NO RECOVERY) and now I got second full back on date : 26-05-2017 , now I want to restore that full backup on previous restored Full back on my client …
How to retrieve current month in SSRS expression
I want to get current month as default value of a parameter. I’ve come up with (which does not work): Answer If you want to get the month as an int that goes from 1 to 12, you can use this This answer was based on the official documentation that you can see in here – http://technet.microsoft.com/e…
SQL SUM Group by – based on ‘group’ from another table
I hope I am explaining this correctly. I have 2 tables, with first table (table1) +————+——+——-+——-+ | Date | Item | Block | Total | +————+——+——-+——-+ |…
MSSQL Geometry, distance from point inside shape to closest edge
I have a shape file that I have imported in to MSSQL as a table with a geometry column. The geometry column is essentially the outline of the UK coastline. What I have been asked to do is to be able to supply latitude/longitude and calculate the closest distance to the coast I have established that the proble…
There is already an object named ‘#tmptable’ in the database
I´m trying to execute stored procedure but I get an issue of an existing temporal table, but I just create one time and use into another part of code SELECT … INTO #tmpUnidadesPresupuestadas FROM …
How to convert date time format in SQL Server like ‘2017-03-04 10:07:03.490’ to date format which is seperated by – like ‘2-11-2016’
I am tying to make date comparison with the query but it throws this error: Msg 242, Level 16, State 3, Line 1 The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. My application passes data in ’01/05/2017′ format and the date information in SQL Server i…