Wednesday, December 26, 2012

Parsing a delimited string in SQL

 Most of the time we required the delimited strings to be added in database. today i come up with some simple solution. which will read the string and specified delimited character and base on that it will divide the string and split it across.

(@String varchar(8000), @Delimiter varchar(10) )
RETURNS @RESULTS TABLE (ID int identity(1,1), Val varchar(50))
DECLARE @Value varchar(100)
WHILE @String is not null
SELECT @Value=CASE WHEN PATINDEX('%'+@Delimiter+'%',@String) >0 THEN LEFT(@String,PATINDEX('%'+@Delimiter+'%',@String)-1) ELSE @String END, @String=CASE WHEN PATINDEX('%'+@Delimiter+'%',@String) >0 THEN SUBSTRING(@String,PATINDEX('%'+@Delimiter+'%',@String)+LEN(@Delimiter),LEN(@String)) ELSE NULL END

You can call this function in your query and it will return the result.(as show in img)

select * from dbo.ParseValues('This;is;a;delimited;string;value',';')

and here is your result..

 Hope this will helps you, Please put your comments or dought to help others.

Monday, June 18, 2012

Jquery copy to clipboard

Hi, after long time right? yea... 

anyways after long time i am decided to get back again on blogger :) and make this blogger active and helpful to others.

today i come up with some tricks on javascript or on jquery . its a Copy to clipboard.
In IE we have direct window option to make the copy to clipboard code event , but if you try to do same with Firefox or other it wont work 

so i thought let add some trick to make the copy thing easy :).

Find my below code and put it in the head section

<script type="text/javascript" src=""> </script>

<script type="text/javascript" src="js/jquery.zclip.js"> </script>

    <script type="text/javascript">
        $(document).ready(function() {
                path: 'js/ZeroClipboard.swf',
                copy: function() { return $('input#dynamic').val(); }


and insert this section on your body part.

<br />
        <a href="#" id="copy-dynamic">Click here to copy the value of this input:</a>
        <input style="width: 300px; margin-left: 15px;" type="text" id="dynamic" value="Insert any text here." onfocus="if(this.value=='Insert any text here.'){this.value=''}" onblur="if(this.value==''){this.value='Insert any text here.'}" />

lets download the swf from GitHubs and put it in your js directory accordingly.

now simple run the application , type the text on the textbox and click on copy button it will copy it in your system just like (Ctrl + C).

Put your comments or suggestion to make this thread active and popular.