July 22, 2012 at 10:24 pm
I am populating a temp table with data drawn from a text defined field in a data table.
I can get the first 8000 characters using : set tm.cntct_notes = convert(varchar(8000), notes.note)
How do I access the next and subsequent blocks of 8000 characters from this notes entry?
Thanks,
Peter
July 22, 2012 at 10:57 pm
PeterR-1037872 (7/22/2012)
I am populating a temp table with data drawn from a text defined field in a data table.I can get the first 8000 characters using : set tm.cntct_notes = convert(varchar(8000), notes.note)
How do I access the next and subsequent blocks of 8000 characters from this notes entry?
Thanks,
Peter
Hey Peter,
User SUBSTRING function for both the cases.
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
July 23, 2012 at 8:40 am
If you want/need a more detailed response you will need to provide a more detailed post. Take a look at the first link in my signature about best practices when posting questions. The time you spend will be rewarded with tested, accurate and fast code.
_______________________________________________________________
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/
July 23, 2012 at 8:53 am
Try using VARCHAR(MAX) instead for VARCHAR(8000)
For details check this link: http://www.sqlservercentral.com/Forums/Topic647815-145-1.aspx
- Lokesh
~ Lokesh Vij
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
July 23, 2012 at 12:44 pm
lokeshvij (7/23/2012)
Try using VARCHAR(MAX) instead for VARCHAR(8000)For details check this link: http://www.sqlservercentral.com/Forums/Topic647815-145-1.aspx
- Lokesh
The OP may be trying to avoid off page storage of certain parts of data which VARCHAR(MAX) would not accomplish.
now for some quick sample code to partially answer the OP's Question (since there is no sample data or ddl this is as good as i can get)
DECLARE @LongString VARCHAR(MAX)
SET @LongString = (SELECT REPLICATE(CAST('abcdefghijk' AS VARCHAR(MAX)),900))
SELECT SUBSTRING (@LongString,(8000*N) + 1 ,8000)
FROM Tally
WHERE N*8000 < LEN(@LongString)
If you dont know what a tally table is you can read about them here http://www.sqlservercentral.com/articles/T-SQL/62867/. The above code uses a 0 based tally table.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
July 23, 2012 at 4:42 pm
Problem solved - Thanks for the advice.
The substring solution worked, but a string length of 8000 would only return 4200, so I ended up using the following:-
settm.cntct_notes1 = substring(notes.note, 1, 4200),
tm.cntct_notes2 = substring(notes.note, 4201, 4200),
tm.cntct_notes3 = substring(notes.note, 8401, 4200)
Thanks again,
Peter
July 23, 2012 at 10:39 pm
PeterR-1037872 (7/23/2012)
Problem solved - Thanks for the advice.The substring solution worked, but a string length of 8000 would only return 4200, so I ended up using the following:-
settm.cntct_notes1 = substring(notes.note, 1, 4200),
tm.cntct_notes2 = substring(notes.note, 4201, 4200),
tm.cntct_notes3 = substring(notes.note, 8401, 4200)
Thanks again,
Peter
What are you basing that on. What you see on the display? The display limits how many characters will be returned. Do a LEN() of your substrings and see.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply