Posts

How to Clean unwanted symbols in a Number column In SQL server ?

Image
. How to clean a phone Number In SQL Server ?       I have a table like this. In this table i want to display phone number without (.) symbol. for this we suppose to create a function. Table info: CREATE A USER DEFINED FUNCTION :-  USE BELLOW CODE TO CREATE A FUNCTION IN SQL SERVER(SSMS) create   function  Udf_getNumber   (  @String  Nvarchar ( 200 )) Returns   nvarchar ( 200 ) As Begin Declare  @intalpha  int set  @intalpha  =   PATINDEX ( '%[^0-9]%' , @String ) Begin   while  @intalpha  > 0 Begin set   @String  = STUFF ( @String , @intalpha , 1 , '' ) set  @intalpha  = PATINDEX ( '%[^0-9]%' , @String ) end end Return   isnull ( @String , 0 ) end once create the function use this function to get desired output  note:- use function Fully Qualified name (schema name. function name eg  dbo . Udf_getNumber ...

What is HFT ?

Image
High-frequency trading (HFT) is a type of algorithmic trading that uses high-speed computers and advanced algorithms to execute trades at a very high frequency, often in milliseconds or even microseconds. HFT is typically used to take advantage of small price movements in the market. HFT strategies are designed to exploit market inefficiencies, such as latency (the time it takes for a trade to be executed) and bid-ask spreads (the difference between the highest price a buyer is willing to pay for a security and the lowest price a seller is willing to accept). HFT traders use a variety of methods to gain an edge in the market, including: Co-location: This is the practice of physically locating a trader's computer servers in the same facility as the exchange's servers, which can reduce latency and give the trader a faster connection to the market. Order spoofing: This is the practice of placing and then quickly canceling large numbers of orders to create the illusion of demand fo...

What is Algo Trading ?

Image
Algorithmic trading, also known as algo trading, is a type of trading that uses computer algorithms to automatically make trades based on certain conditions or signals. Algo trading is widely used in financial markets, such as the stock market, to execute trades quickly and efficiently. There are several types of algo trading strategies, including: High-frequency trading (HFT): This is a type of algo trading that uses high-speed computers and advanced algorithms to execute trades at a very high frequency, often in milliseconds or even microseconds. HFT is typically used to take advantage of small price movements in the market. Statistical arbitrage: This is a type of algo trading that uses statistical methods to identify and exploit inefficiencies in the market. The strategy looks for pairs of stocks that have a historical relationship, such as a correlation or cointegration, and then makes trades to take advantage of any deviations from that relationship. Trend following: This is a ty...

python Database connections- MS SQL server connection.

Image
Microsoft SQL Server already installed in your local machine and you need to connect with python  using  Text editor or IDE  then this  article for you  to connect database you need pyodbc  library. pyodbc is an open source Python module that makes accessing ODBC databases simple. It implements the  DB API 2.0  specification but is packed with even more Pythonic convenience. The easiest way to install is to use pip: using CMD  and bellow command  it will install pyodbc pip install pyodbc Then using sublime or VS code or any IDE import  pyodbc library  if your  a user then use bellow code  import pyodbc conn= pyodbc.connect(         host= "DESKTOP-V5F828B\SQLEXPRESS" ,         USER = "Testlogin",         password = "1234" ,         Driver= 'ODBC Driver 13 for SQL Server' ,         Trusted_connection= 'no' ,   ...

Views in SQL

What is a View? A view is nothing more than a  saved SQL query . A view can also be considered as a  virtual table . View script  Create view VIEW_NAME AS SELECT T1. CUSTEMOR _NAME , T1.CUST_ID , T1.Address,  T2.Order_units From CUSTERMORTABLE  AS T1 Inner join   ORDERS AS T2 ON T1.CUST_ID =T2.CUST_ID Where order_units > = 60  

SQL Functions

Functions in SQL server can be broadly divided into 2 categoris 1.  Built-in functions 2.  User Defined functions There are several built-in functions,we will look at the most common string functions available. Functions – Function accept only input parameters, perform actions and return the result. A  function  can   return an only a single value or a table. We can't use a  function  to Insert, Update, Delete records in the database tables. Note – some functions need input parameters , some functions not required   Different Types of  SQL  Server &  SQL  Database  Functions .-              1.Aggregate functions  2.Mathematical functions   3.Conversation functions   4.Null functions   5.String functions (Text Functions)   6.Date and Time functions   7.Analytical functions  -(Ranking Functions ,Window...

Group by and Having ,Order by

Image
Group By -  In SQL Server we have got lot of aggregate functions. Examples 1. Count() 2. Sum() 3. avg() 4. Min() 5. Max() Group by  clause is used to group a selected set of rows into a set of summary rows by the values of one or more columns or expressions. It is always used in conjunction with one or more aggregate functions. I want an sql query, which gives total salaries paid by City. The output should be as shown below. Query for retrieving total salaries by city : We are applying SUM() aggregate function on Salary column, and grouping by city column. This effectively  adds, all salaries of employees with in the same city. Select  City,  SUM (Salary)  as  TotalSalary  from  tblEmployee Group by  City Note:  If you omit, the group by clause and try to execute the query, you get an error -  Column 'tblEmployee.City' is invalid in the select list  because it is not ...

SQL for Analytics

Click on bellow Links to explore more   part 1 -   How to CREATE DATABASE AND TABLE and DATA TYPES information part 2 -   working with DATABASE, What is Constraints ?what are they Part 3 -  All about Group by, Having ,Order by PART 4 -  FUNCTIONS IN SQL PART 5 -  Joins in SQL

class 5 - SQL Operators

SQL Arithmetic Operators Operator Description Example + Add Try it - Subtract Try it * Multiply Try it / Divide Try it % Modulo Try it SQL Bitwise Operators Operator Description & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR SQL Comparison Operators Operator Description Example = Equal to Try it > Greater than Try it < Less than Try it >= Greater than or equal to Try it <= Less than or equal to Try it <> Not equal to Try it SQL Compound Operators Operator Description += Add equals -= Subtract equals *= Multiply equals /= Divide equals %= Modulo equals &= Bitwise AND equals ^-= Bitwise exclusive equals |*= Bitwise OR equals SQL Logical Operators Operator Description Example ALL TRUE if all of the subquery values meet the condition Try it AND TRUE if all the conditions separated by AND is TRUE Try it ANY TRUE if any of the subquery values meet the condition Try it BETWEEN TRUE if the operand is within the...