July 10, 2020

SQL Server queries

Ads

SQL Server

SQL Server Alter Function

How to update the code of an SQL Server function without deleting it? The solution is to update its definition using the SQL Server Alter Function command. The query updates the function already created in the database. This new code returns not only the customer name, but also the customer

SQL Server

SQL Server Create Function

How to write an SQL Server Create Function query? This SQL Server function takes as a parameter the customer number and returns the customer name. Indeed, the function stores the customer name in the @CustomerName variable, and it returns it as a result.   SQL Server Create Function The different steps

SQL Server

Remove SQL Server new line

How to remove SQL Server new line? This post propose a simple SQL Server query to process a string variable and remove the new line character. Technically we replace the new line by nothing. The SQL Server code for a new line is CHAR(13)+CHAR(10).     You want to remove it to

SQL Server

Display SQL Server date full month name

How to display SQL Server date full month name? Which is to say with the complete month names like January, February, March, April, May, etc. written out in full. This query shows you how to get the full month names from the current date or any other date.   Indeed,

SQL Server

SQL Server list all the tables and disk space

List all existing tables from an SQL Server database can be very convenient especially to analyze the disk usage and the free disk space used by each table. Three different ways, but similar are presented here to display SQL Server tables and disk space used by each table. The third solution

Blue and grey gearwheels image
SQL Server

SQL Server UNPIVOT function example

How to use a T-SQL query to transform columns to rows? It’s possible with this simple SQL Server UNPIVOT function example. The T-SQL Unpivot function can do it in one single query. In this example, only the six first months of the year are used as columns, namely January to

SQL Server

Check SQL Server table last update and access

How to check SQL Server table last update and access? Check the last access and update with a simple SQL query? Thanks to SQL Server RDBMS system tables, a query allows you to display the last changes done. We can apply it to any SQL Server table or view, like

SQL Server

SSMS option to check object existence in SQL scripts

How to add or remove the object existence checks in SQL creation scripts with SQL Server Management Studio? To add dynamically the existence check before generating the create statement for you SQL Objects like tables, views,  functions or stored procedures, it’s easy. Simply activate this SSMS option to check object existence in

SQL Server

List User Defined Table Types with SQL Server

How to list User Defined Tables Types of your SQL Server database? First of all, users declare User Defined Table Type as a particular table structure in the database. A database user declares it and not the system. It’s good to ensure users can’t insert data with different types or

No Picture
SQL Server Tables

How to Drop a SQL Server table?

How to drop a SQL Server table? How to drop it without checking if the table exists ? Assume the object is already in the database. How to Drop a SQL Server table from the database with a query? Here is a SQL script to create a SQL Server table.

SQL Server Errors

SQL Server Truncate Table Error Cannot find the object

In SQL Server, to clear the full content of a table, the fastest way is to run a Truncate Table query. The Truncate is different from the Delete From query because it empties all the lines in the table without a Where clause, it’s a DDL SQL operation (Database Definition

No Picture
SSAS Tabular Errors

SSAS Tabular Model error opening

When opening an SSAS Tabular Model Visual Studio SSDT (SQL Server Data Tools), if for example you loose your network connectivity to the repository for a few seconds, then the SSAS Tabular Model don’t open. Error: Can’t open the SSAS Tabular Model from Visual Studio SSDT. Tabular Model Designer error:

DAX functions

Calculate Last Year Value in DAX for Power BI

How to calculate the last year value with DAX in Power BI? Simply use the available DAX CALCULATE function combined with the PREVIOUSYEAR function. In financial Dashboard and Reports, use the previous year value for comparison and variance calculation with the current year. Indeed analysing financial figures is often about comparison. How to calculate the last year value with DAX in Power BI using a formula? The first option is to

No Picture
MS BI Abbreviations

DAX – Data Analysis Expression

DAX stands for Data Analysis Expression, it’s the Microsoft language to manipulates data in Microsoft SSAS Tabular cubes as well as in Power BI, and also in Excel PowerPivot. DAX: Data Analysis Expression The DAX library is a Powerful and user-friendly Microsoft library of different type of functions addressing different

SQL Server Errors

SQL Server Database does not exist sp_MSforeachdb

With SQL Server, when using the sp_MSforeachdb system stored procedure, the system displays this error “Database does not exist. Make sure that the name is entered correctly.” . The stored procedure displays the error because the database tries to access a database that does not exist in your SQL Server

SQL Server

SQL Server Alter Function

How to update the code of an SQL Server function without deleting it? The solution is to update its definition using the SQL Server Alter Function command. The query updates the function already created in the database. This new code returns not only the customer name, but also the customer

SQL Server

SQL Server Create Function

How to write an SQL Server Create Function query? This SQL Server function takes as a parameter the customer number and returns the customer name. Indeed, the function stores the customer name in the @CustomerName variable, and it returns it as a result.   SQL Server Create Function The different steps

ADS