March 22, 2013 at 10:45 am
hi guys,
can anyone help me
1.i need to Write a SP to accept comma separated values and return as list of string values
2. i need to Write a SP to find occurences of a character in a string
3. i need to Write a SP to find number of words in a sentence
March 22, 2013 at 12:11 pm
Sounds like homework to me.
March 22, 2013 at 12:17 pm
Am trying to practice but I didn't can you help me
March 22, 2013 at 12:27 pm
There are some excellent string splitter functions you can search for on this site (Jeff Moden's is the one most recommended for speed and flexibility). Any of these would be good illustrations of the concepts you need to solve your exercises. Posting what you have tried so far will allow the folks here to steer you in the right direction without doing the work for you. Most folks here balk at providing the complete answer for these types of exercises because it tends to minimize the actual amount of knowledge gained by the requestor.
March 22, 2013 at 12:32 pm
For #1 and #3, try Jeff Moden's string splitter. http://www.sqlservercentral.com/articles/Tally+Table/72993/%5B/url%5D
For #2, Sean Lange posted this great approach earlier today for a similar request:
with EconSearch(SomeValue) as
(
select 'D.01.01.01' union all
select 'D.01.01.02' union all
select 'D.01.01.03' union all
select 'D.01.01.03.00'
)
select len(SomeValue) - len(Replace(SomeValue, '.', '')) as NumberOfPeriods
from EconSearch
March 22, 2013 at 12:34 pm
Yes splitting your parameter is the way to go here. All of these can easily be done using Jeff's splitter. You can find it by following the link in my signature for splitting strings.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 22, 2013 at 12:36 pm
Ed Wagner (3/22/2013)
For #1 and #3, try Jeff Moden's string splitter. http://www.sqlservercentral.com/articles/Tally+Table/72993/%5B/url%5DFor #2, Sean Lange posted this great approach earlier today for a similar request:
with EconSearch(SomeValue) as
(
select 'D.01.01.01' union all
select 'D.01.01.02' union all
select 'D.01.01.03' union all
select 'D.01.01.03.00'
)
select len(SomeValue) - len(Replace(SomeValue, '.', '')) as NumberOfPeriods
from EconSearch
Thanks Ed. As soon as I posted I suddenly had that feeling that I just posted to the wrong thread having seen code that looked eerily familiar. 😛
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 22, 2013 at 12:37 pm
1.i need to Write a SP to accept comma separated values and return as list of string values
If you're on SQL 2008 or above then why would you ever want to do that when you can use a Table-Valued Parameter?
Table-Valued Parameters (Database Engine) - SQL Server 2008
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply