Why You Should Always Use Unicode For Dynamic SQL

  Рет қаралды 734

Erik Darling (Erik Darling Data)

Erik Darling (Erik Darling Data)

Күн бұрын

Пікірлер: 21
@RomanPeralta
@RomanPeralta 24 күн бұрын
Long videos are like second breakfast-there's always more than you expect!
@ErikDarlingData
@ErikDarlingData 24 күн бұрын
I hope this is a good thing. Second breakfast sounds like first nap.
@jiridolezalcz
@jiridolezalcz 23 күн бұрын
Useful, many thanks. I wonder if there is any possibility for automation or code-smell-checking? Developer is a human beeing not fully concentrated for all of the details that should be met everytime.
@ErikDarlingData
@ErikDarlingData 23 күн бұрын
I haven't seen any good ones publicly available, no.
@DBNinj4
@DBNinj4 23 күн бұрын
Anyone complaining about long videos has obviously never spent hours troubleshooting code, only to find that the code is fine but the datatypes act differently under different collations.
@ErikDarlingData
@ErikDarlingData 23 күн бұрын
HAHAHA, you know, that's a really funny point.
@mattcargile
@mattcargile 24 күн бұрын
I want your datalength!
@ErikDarlingData
@ErikDarlingData 24 күн бұрын
That could get expensive.
@ntobergta
@ntobergta 25 күн бұрын
It’s about how rounded it is
@ErikDarlingData
@ErikDarlingData 25 күн бұрын
heyyyy wait a minute
@jackiecooper9439
@jackiecooper9439 25 күн бұрын
When making a dynamic SQL string using multiple NVARCHAR(MAX) variables why does it sometimes not take more than 4K characters? Did any1 else face this issue here? On stack overflow I read it's due to 8K page size. But it happens only on some complex dynamic queries and I am not able to recreate it in simple scenarios.
@ErikDarlingData
@ErikDarlingData 24 күн бұрын
Well, the SO explanation is wrong. Leave that out of your brain. I think you're confusing what can be put into a string vs what can be printed from a string. PRINT statements have an 8000 byte (not character) maximum, so printing out unicode (nvarchar) strings with standard ASCII characters can only display the first 4000 (each character being two bytes instead of one). If you use print and substring, you can get deeper into longer strings. You can run into situations where using + to concatenate strings that don't have an explicitly declared length can suffer from implicit conversions from max to shorter byte lengths. That's why to be safe I end up explicitly casting shorter strings that I'm concatenating in to nvarchar max.
@jackiecooper9439
@jackiecooper9439 23 күн бұрын
@@ErikDarlingData Thanks for replying. The LEN itself is 4k charcters. Eg: I have two NVARCHAR (MAX) variables @Sql1 and @Sql2 each are individually built using multiple sting concatenations using '+'. The final SQL string to be executed is built as follows: Declare @FinalSql NVARCHAR(max) Set @FinalSql = @Sql1 + @Sql2 Now the LEN( @Sql1) is 4k. So the query has lost all the characters after 4k characters, thus giving me an apt syntax error. I use PRINT CAST (@FinalSql as NTEXT) to print everything and @Sql1 portion is indeed cut off at precisely 4k characters.
@jackiecooper9439
@jackiecooper9439 23 күн бұрын
@@ErikDarlingData So I guess the culprit is concatenations using '+'. Currently I'm tricking by; Set @SQL1 = @Sql1 /*contains the string almost upto 4k characters*/ + -- rest of the concatenations. Now the @Sql1 is correctly formed.
@ErikDarlingData
@ErikDarlingData 23 күн бұрын
@@jackiecooper9439 well, I'm not entirely sure based on your description and solution what the problem is, but like I said before, tacking on shorter strings can often result in strange truncation issues. An alternative way to make sure the contents are fully displayed would be something like: SELECT ( SELECT [processing-instruction(_)] = @sql1 FOR XML PATH(''), TYPE );
@clerincg
@clerincg 25 күн бұрын
Don't shorten your videos too much or I'll have to shorten my lunch break accordingly 😁 Erik, are you ever concerned the Unicode strings take twice as much storage as non-Unicode? If you will never (well, never say never, right??) have Unicode characters, is it worth the storage overhead?
@ErikDarlingData
@ErikDarlingData 25 күн бұрын
No, I honestly don't care about that. It falls into the category of 32 bit problems, like index fragmentation, page splits, and other goofy memes from the bad old days.
@TZH474
@TZH474 25 күн бұрын
Is that “live Elvis entertainment “?
@ErikDarlingData
@ErikDarlingData 25 күн бұрын
You'd have to ask our AI overlords.
@douglascoats7081
@douglascoats7081 24 күн бұрын
I dont have an issue with your length. You are long enough lol seriously though who is actually complaining about 15 minute videos?
@ErikDarlingData
@ErikDarlingData 24 күн бұрын
It's the internet people complain about everything
Signs You Need Dynamic SQL In Your SQL Server Queries
15:08
Erik Darling (Erik Darling Data)
Рет қаралды 1,3 М.
A Little About Working With Binary and Varbinary Data In SQL Server
14:16
Erik Darling (Erik Darling Data)
Рет қаралды 472
Family Love #funny #sigma
00:16
CRAZY GREAPA
Рет қаралды 38 МЛН
the balloon deflated while it was flying #tiktok
00:19
Анастасия Тарасова
Рет қаралды 35 МЛН
Elza love to eat chiken🍗⚡ #dog #pets
00:17
ElzaDog
Рет қаралды 22 МЛН
A Video For My Friend Brent About Automatic Tuning
10:35
Erik Darling (Erik Darling Data)
Рет қаралды 1 М.
SQL Indexes Explained in 20 Minutes
19:31
developedbyed
Рет қаралды 11 М.
Fundamentals of Vacuum in PostgreSQL: Module 1
12:06
Smart Postgres
Рет қаралды 1,1 М.
Debugging a Complex T-SQL Issue
1:00:54
Brent Ozar Unlimited
Рет қаралды 6 М.
Performance Pains With NOT IN And NULLable Columns In SQL Server
12:36
Erik Darling (Erik Darling Data)
Рет қаралды 843
Office Hours: Ask Me Anything About SQL Server and Azure SQL DB
27:40
Brent Ozar Unlimited
Рет қаралды 2,3 М.
Advanced RAG: Combining RAG with Text-to-SQL
15:08
LlamaIndex
Рет қаралды 3 М.
Reacting to Controversial Opinions of Software Engineers
9:18
Fireship
Рет қаралды 2,1 МЛН
A Little About Paging Queries And Batch Mode In SQL Server
19:45
Erik Darling (Erik Darling Data)
Рет қаралды 1 М.
Of RECOMPILE Hints And Query Store: Where Are My Parameter Values?!
11:53
Erik Darling (Erik Darling Data)
Рет қаралды 286