Header Ads Widget

SQL Server String Functions: LEFT, RIGHT, LEN (हिंदी में)

SQL Server String Functions: LEFT, RIGHT, LEN (हिंदी में)

SQL Server String Functions: LEFT, RIGHT, LEN (हिंदी में)

🔑 Memory में रखें (Definition)

String Functions SQL Server में ऐसे functions हैं जो text (varchar/nvarchar) values को manipulate करने के लिए उपयोग होते हैं। LEFT() string की शुरुआत से characters काटता है, RIGHT() अंत से, और LEN() किसी string की लंबाई बताता है।

🧾 Syntax

  • LEFT(string, number) – string के start से characters return करता है।
  • RIGHT(string, number) – string के end से characters return करता है।
  • LEN(string) – string की length return करता है।

📋 Demo Table: Customers

CREATE TABLE Customers (
    CustID INT,
    FullName NVARCHAR(100)
);

INSERT INTO Customers VALUES
(1, 'Ravi Sharma'),
(2, 'Neha Mehta'),
(3, 'Amit Kumar');

🧪 Example 1: LEFT()

SELECT FullName, LEFT(FullName, 4) AS First4 FROM Customers;

🧪 Example 2: RIGHT()

SELECT FullName, RIGHT(FullName, 5) AS Last5 FROM Customers;

🧪 Example 3: LEN()

SELECT FullName, LEN(FullName) AS NameLength FROM Customers;

📊 Output (उदाहरण स्वरूप)

FullNameLEFT(4)RIGHT(5)LEN()
Ravi SharmaRaviharma11
Neha MehtaNehaMehta11
Amit KumarAmitKumar10

🧠 INTERVIEW QUESTIONS (with Answers)

  1. Q: LEFT() function क्या करता है?
    Ans: किसी string के start से n characters return करता है।
  2. Q: RIGHT() function कब use होता है?
    Ans: जब हमें string के end से characters चाहिए होते हैं।
  3. Q: LEN() function क्या return करता है?
    Ans: String की total length (character count)।
  4. Q: क्या LEN() space को गिनता है?
    Ans: हाँ, बीच के spaces को गिनता है लेकिन trailing spaces नहीं।
  5. Q: LEFT/RIGHT का practical उपयोग कहां होता है?
    Ans: जैसे customer code, नाम के initials, या last digits निकालने में।

अगर यह पोस्ट पसंद आई हो तो Job Oriented Academy को लाइक, शेयर और सब्सक्राइब करना न भूलें! ❤️

Post a Comment

0 Comments