RSS

Get document Extension from the Sql To Display in Gridview

23 Aug

This code for Testing Propose in sql Query Analyzer

This code for Testing Propose in sql Query Analyzer

declare @path varchar(2000)

set @path=’20108211632495_CustomPaging Code C-Sharp.docx’

select substring(@path,charindex(‘.’,@path)+1,len(@path))

Description

Declare Variable to Store the Image or document Name with Extenshion

Then Save document name in variable

Get The Ex of the Document

Substring Syntax:

SUBSTRING ( expression ,start ,length )

Arguments

expression

Is a character string, binary string, text, image, a column, or an expression that includes a column. Do not use expressions that include aggregate functions.

start

Is an integer that specifies where the substring begins.

length

Is a positive integer that specifies how many characters or bytes of the expression will bereturned. If length is negative, an error is returned.

SELECT au_lname, SUBSTRING(au_fname, 1, 1)

FROM authors

ORDER BY au_lname

Here is the result set:

au_lname

—————————————- –

Bennet                                   A

Blotchet-Halls                           R

Carson                                   C

DeFrance                                 M

del Castillo                             I

Yokomoto                                 A

(23 row(s) affected)

CHARINDEX

Syntax


CHARINDEX ( expression1 ,expression2 [ , start_location ] )

Arguments


expression1

Is an expression that contains the sequence of characters to be found. expression1 is an expression of the character string data type category.

expression2

Is an expression, typically a column searched for the specified sequence. expression2is of the character string data type category.

start_location

Is the character position to start searching for expression1 in expression2. If start_location is not specified, is a negative number, or is zero, the search starts at the beginning of expression2. start_location can be of type bigint.

Return Types


bigint if expression2 is of the varchar(max), nvarchar(max) or varbinary(max) data types, otherwise int.

Examples


The following code example returns the position at which the sequence of characters bicycle starts in the DocumentSummary column of the Document table.

USE AdventureWorks;

SELECT CHARINDEX(‘bicycle’, DocumentSummary)

FROM Production.Document

WHERE DocumentID = 3;

Here is the result set.

———–

48

The following example uses the optional start_location parameter to start looking for bicycle in the fifth character of the DocumentSummary column.

SELECT CHARINDEX(‘bicycle’, DocumentSummary, 5)

FROM Production.Document

WHERE DocumentID = 3;

Here is the result set.

———–

48

The following example shows the result set when expression1 is not found within expression2.

SELECT CHARINDEX(‘bike’, DocumentSummary)

FROM Production.Document

WHERE DocumentID =6;

Here is the result set.

———–

0

The following example uses the COLLATE function.

SELECT CHARINDEX ( ‘Test’, ‘Das ist ein Test’  COLLATE Latin1_General_BIN);

Solution#2 With Query

This is Actual Query to get the Extension of Document which save in db

SELECT DocumentID,

DocumentTitle,

substring(DocumentPath,charindex(‘.’,DocumentPath)+1,len(DocumentPath)) DocumentType,

DocumentPath,

EnteredDate,

EnteredBy,

ModifiedDate,

ModifiedBy,

case DocumentStatus

when 1 then ‘Active’

else

‘Inactive’

end DocumentStatus

FROM tblDocument

Thank for visit…………..if this code for helpful for you then kindly comments……

Sajjad Ahmed

Sofware Eng(ITBeams(Pvt) Ltd Lahore)


Advertisements
 
1 Comment

Posted by on August 23, 2010 in SQL Query

 

One response to “Get document Extension from the Sql To Display in Gridview

  1. Sampson

    October 22, 2013 at 9:12 am

    The DataGridView provides a variety of Expression Editor to create editing expressions for GridView control.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: