Showing posts with label Function. Show all posts
Showing posts with label Function. Show all posts

3 December 2021

substring function in react js

import React from 'react';

function SubstringEXP(props) {
    var str = "Hello world, react js SubString example";
    return (
        <div>
            <div><h1>SubString example</h1></div>
            {str.substring(0,10)}
        </div>
    );
}

export default SubstringEXP;

Github link: https://github.com/adi501/react-js-example

22 July 2021

Arrow function in javascript

const sum = (a, b) => a + b;
console.log(sum(2, 5));

Output: 7

Github link : https://github.com/adi501/JavaScriptExamples.git





 

2 April 2020

State From Parent To Child Class & Child Function in react js

  • Create Components folder under src folder
  • Add StateFromParentToChild.js file and add below Code
import React, { Component } from "react";

class StateFromParentToChild extends Component {
constructor() {
super();
this.state = {
name: "Adi"
};
}
render() {
return (
<div>
State From Parent To Child Class & Child Function
<div>Parent Class</div>
<JTP name={this.state.name} />
<PopsInFunEXP1 name={this.state.name} />
</div>
);
}
}
class JTP extends Component {
render() {
return (
<div>
<div>Child Class</div>
<div>Welcome to {this.props.name}</div>
</div>
);
}
}
function PopsInFunEXP1(props) {
return (
<div>
<div>Child Funtion</div>
<div>{props.name}</div>
</div>
);
}
export default StateFromParentToChild;
  • Open App.js file and update code as below\
import React from "react";
import ReactDOM from "react-dom";
import StateFromParentToChild from "./components/StateFromParentToChild";

function App() {
return (
<div className="App">
<StateFromParentToChild />
</div>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Output:



27 March 2020

Split Comma Separated List Without Using a Function in SQL Server

DECLARE @t TABLE
(
EmployeeID varchar(100),
Certs VARCHAR(8000)
)
INSERT @t VALUES ('Param1:','B.E.,MCA, MCDBA, PGDCA'), ('Param2:','M.Com.,B.Sc.'), ('Param1:','M.Sc.,M.Tech.')

SELECT EmployeeID,
EmployeeID+LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Certs
FROM
(
SELECT EmployeeID,CAST('<XMLRoot><RowData>' + REPLACE(Certs,',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
FROM   @t
)t
CROSS APPLY x.nodes('/XMLRoot/RowData')m(n)


Output:

19 April 2014

User Defined Trim Function in SQL Server



SQL Server has RTRIM() function that truncates all trailing blanks:

SELECT RTRIM('Hello world ') as Result;



There is also LTRIM() function that truncates all leading blanks:

SELECT LTRIM(' Hello world') as Result;



There is no TRIM() function that truncates all trailing and all leading blanks.
You can do that by combining RTRIM() and LTRIM() function in one query:

SELECT LTRIM(RTRIM(' Hello world ')) AS Result;



Or you can create a User Defined Function (UDF) that truncates all trailing and all leading blanks:

CREATE FUNCTION dbo.ufnTRIM(@string NVARCHAR(4000))
RETURNS NVARCHAR(4000)
BEGIN
RETURN LTRIM(RTRIM(@string))
END
GO

To run the new function:

SELECT dbo.ufnTRIM(' Hello world ') AS Result;

User Defined Function (UDF) to Determine if a String is a Palindrome

           Palindrome is a word or a phrase that reads the same in both directions. To check if a string is a palindrome in SQL Server, you can use REVERSE built in string function that returns the reverse order of a string value, and compare it to the original string.We will create a User Defined Function (UDF) that accepts a string and checks if the string (with spaces removed from it) is a palindrome:

CREATE FUNCTION ufnPalindromeCheck (@MyString nvarchar(256))
RETURNS varchar(50)
AS
BEGIN
DECLARE @ReturnString varchar(50)
SET @ReturnString = CASE WHEN REVERSE (REPLACE(@MyString, ' ', '')) = (REPLACE(@MyString, ' ', ''))
THEN 'The string is a palindrome'
ELSE 'The string is NOT a palindrome'
END
RETURN @ReturnString
END
GO

To use this user-defined function:

SELECT dbo.ufnPalindromeCheck ('Step on no pets')



SELECT dbo.ufnPalindromeCheck ('So many dynamos')

11 February 2014

What is Difference between Function and Store Procedure in sqlserver?

Function

1. Function must be returning the result set values. Or single column values
2. Function only input parameters
3. Function can use in Sql Statement Having/Where/Select sections anywhere.
4. Function can return values so we can use joins in any other tables
5. Function can call from procedure

Store Procedure

1.Store procedure no need to return values.
2. Store procedure allow input/output parameters
3.Store procedure not allow where/Having/select sections anywhere in Sql statements
4.Procedure can’t call from function