« first day (2102 days earlier)      last day (2767 days later) » 

6:33 AM
1
Q: How can i limit the number of rows a user can update?

Keeghan McGarryOne of our Business Research Analysts has a habit of accidentally updating without a where clause. Preferably the solution is better training and following a procedure like writing a SELECT before UPDATE. Or just security policies... However, those things aren't going to happen soon. So I woul...

 
6
Q: Can you prevent more than X number of rows being updated in SQL Server?

Chad CookIs there a way to configure SQL Server to limit the number of rows than an update statement can modify? Say I wanted the limit to be 30,000 rows and someone fired an update that would modify 45,000 rows, they would receive an error or some other preventive message.

 
7:30 AM
Mornin'
 
7:52 AM
Morning
 
@PaulWhite now that wasn't me
but, of course, these are always implied
 
8:12 AM
Help please:
0
Q: SQL Server - NTEXT columns and string manipulation

PhilI have a table with an NTEXT column called comments. I have a second string, let's call it anothercomment that needs placing inside a given comments string after the word UPDATEHERE. Casting to nvarchar(max) truncates the comments string, so I cannot use the likes of CHARINDEX() (Msg 8152, Level...

:-)
 
@Phil What do you mean by "Casting to nvarchar(max) truncates the comments string"? There should be no truncation converting ntext to nvarchar(max).
 
Is anothercomment also ntext or varchar or a fixed string in your query?
 
I think it would help if we saw the actual attempts.
 
@TomV A VARCHAR
 
Yes, create table and insert statements please :)
 
8:16 AM
@TomV With an 8k string?
 
not necessarily
 
I'd be interested to see the CHARINDEX expression (including the conversion to nvarchar(max) where it was necessary)
 
` select CHARINDEX(cast(comments as nvarchar(max)),'UPDATEHERE')` gives `Msg 8152, Level 16, State 10, Line 1
String or binary data would be truncated.`
 
Ah, that's easy. Just swap the arguments.
 
LOL
I'm dumb
2
 
8:19 AM
:)
 
To be fair, CHARINDEX and PATINDEX are really counter-intuitive in that regard. All the other string functions accept the subject string as the first argument.
 
morning
 
@AndriyM Yes I remember swearing the first time I worked with NTEXT
 
Operand data type ntext is invalid for add operator.
So how do I concatenate3 strings back together again :P
 
If it's saying "add operator", then perhaps one of the operands ends up as a number (a numeric type) (and so the + is treated as addition rather than concatenation). You either need to cast it as a string explicitly or maybe you could use the CONCAT() function where the arguments are converted implicitly.
 
8:29 AM
@AndriyM I'm on 2008r2, so no CONCAT().
 
Ah, then it should be casting as a string then.
Again, if you show what you are doing, it might be easier to help
 
I'll see if i can put a long ntext value into sql fiddle
 
@Phil could you try
-- Create the table
CREATE TABLE [dbo].[PhilsTable](
[comment] [ntext] NULL,
[anothercomment] [nvarchar](50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];

GO

-- insert very long string
INSERT INTO [dbo].[PhilsTable] (comment, anothercomment) VALUES (N'This is a test UPDATEHERE This is the end of the test' + REPLICATE (N'x' ,1000000 ) , 'this goes in here');

-- verify data
SELECT * FROM [dbo].[PhilsTable];

-- perform replace
SELECT CAST(REPLACE(CAST(comment AS NVARCHAR(MAX)),'UPDATEHERE','UPDATEHERE' + anothercomment) AS NTEXT) FROM [dbo].[PhilsTable];
 
@TomV REPLICATE (CAST(N'x' AS nvarchar(max)), 1000000), or it won't work as expected.
 
@AndriyM Hmm, still provides the same output though
But I admit I was unsure if that replicate was OK with ntext
Tried casting to ntext but that's obviously not allowed
 
8:39 AM
@TomV That insert truncates to 8000 characters
 
but does the select work on your dataset?
 
@TomV What I mean is:
SELECT LEN(REPLICATE (     N'x'                  , 1000000));  -- returns 4000
SELECT LEN(REPLICATE (CAST(N'x' AS nvarchar(max)), 1000000));  -- returns 1000000
 
@Phil And if you apply @AndriyM 's suggestion?
 
That works. I love you all! <3
5
ntext can die a horrible death!
5
Post an answer and i'll give you some love
 
9:16 AM
I don't normally ask questions on here, so goes to show how much it was doing my head in!
 
I like how Tom's answer got away without requiring the question to be updated with the details that actually helped to resolve the issue. "You are probably doing something wrong, try this." Very nice.
 
@AndriyM Yeah I was thinking about how to word that or edit in phils comments from here and then thought "I'm not sure this 'll help that many people in the future so here goes"
The SO way, just post the code and be done with it :)
 
@TomV I was about to excuse myself from answering and I really hated doing that because Phil's question was otherwise well presented. I was really glad you took the trouble of answering it, so thank you, as it happens.
 
9:50 AM
@AndriyM And I was a bit embarrassed to post a joint effort as an answer but figured you wouldn't mind, so I guess it worked out
 
Absolutely
 
10:25 AM
I hope this OP stays around, I used to work with him and he's brilliant
3
Q: Why is the query_hash zero for EXEC statements?

Bert Van LandeghemI'm setting up a monitoring system for SQL Server using Extended Events to find heavy queries as 'production feedback' for our developers. I'm using the events sp_statement_completed and sql_statement_completed, with predicate filters on cpu_time, logical reads, etc. I was hoping to aggregate th...

 
10:41 AM
@TomV I like it when awesome people arrive
 
 
2 hours later…
12:44 PM
Nuke this, please
0
Q: Can't create view

konmaitemI want to create a view like CREATE VIEW monitors_info AS SELECT monitors_id, nom FROM monitors; But, I got this message ERROR: No schema has been selected to create in. (using psql) I don't know what I miss, please help me.

 
JNK
nuked
 
@JNK nice to have you back in action :)
 
JNK
kind of!
 
kind of nice? or kind of back? or kind of action?
 
Can't beat a bit of hot JNK action
 
JNK
1:04 PM
kind of back :)
I make no guarantees! but I am trying
work stuff is a lot more dynamic for me than it used to be
 
@JNK good dynamic or bad dynamic?
or regular dynamic?
 
JNK
just regular
I used to be able to be at my desk and left alone most of the day
now im in meetings or on calls a whole lot
 
poor you
 
Sep 30 at 12:24, by JNK
busy busy busy
 
JNK
I mean it's ok
 
1:08 PM
@JNK this is why I don't plan to be a boss
 
JNK
It's just different
 
(not that I hate people, but meetings make me tired)
 
JNK
yeah meetings wear me out
Wednesday is like all day meeting day
8:45-9:15, 9:45-10:30, 11-12, 2-3, 4-5
I'm fine with it though, my degree is actually in Business Admin I learned SQL by accident
 
@JNK I'm starting to doubt that you really are number 5
 
JNK
I'm ALIVE
 
1:56 PM
0
Q: MSSQL Server 2008 Standard Edition archive large 800GB table

sunilsuranaI have a table which has millions of records being inserted per day since 2011. The data size for that table alone have grown more than 800GB. For me only last 3 months of data is being queried frequently whereas for older data query needs to be done very rarely and it can be done in offline mode...

Peoples...
 
2:12 PM
Microsoft webcast on Dynamics 365, cortana powerbi embedded in your cloud ERP
like what?
15 minutes in and I've already completed my buzzword bingo
 
@TomV 15 minutes in what?
 
the webcast
 
what webcast?
 
3 mins ago, by Tom V
Microsoft webcast on Dynamics 365, cortana powerbi embedded in your cloud ERP
 
@TomV ah, you mean I should read your comments before talking?
 
2:43 PM
user image
4
^^^ This should be in the Help center across all sites
 
2:57 PM
@billinkc Is that your work?
I mean, did you draw that?
 
Goodness no
I am not that clever, nor can I draw worth a damn
 
@AndriyM lol
 
I think my older boy was probably 4 or 5 and asked me to draw our dog. I did my best and when I gave it to him, he busted out laughing "THAT'S NOT A DOG!"
Harsh
No, I purloined that image from the SQL Server Slack channel because it speaks to the support person in me
 
@billinkc Why didn't you create it in photoshop?
 
@billinkc then he realized that you had bought him a cat instead of a dog?
 
3:01 PM
@Lamak I traded him to gypsies for a dog
 
@billinkc I seriously allowed the possibility it was yours. And if it were, my next question was going to be, "Whatever happened to your Photoshopping skills?"
 
My photoshopping skills are only in play if have a base image to start with
 
@billinkc well, you have the one you posted, now you just need to photoshop some faces there
 
I imagine bill telling lamak what to do and lamak screwing up
 
He does that on his own
I'd just get to enjoy the experience of seeing it first hand
 
3:06 PM
yeah, I don't need help for that
@billinkc you need to come to chile and you'll be able to
 
@Lamak It's not so much about help as about asking you afterwards, "Why are you like this?"
 
@AndriyM "to mess with you" is the right answer
 
@Lamak Yes you are clearly absolutely brilliant but a very subtle troll
 
is it ok to feel flattered by that comment?
 
Not much of a difference in pricing based on where I land, which is surprising. Except for Valdiva, why do they think their sh*t doesn't stink?
1200 to 1400 except for Valdiva which is 2241
 
3:11 PM
weird
 
I could visit Paul for 1800, Marian can meet me in Bucharest for 1560, the London boys for 1200 and Tom and Andriy the winners at 1k
 
@billinkc and by that, I mean you
 
@billinkc Nobody wants to come here any more
 
@TomV they found out @billinkc is thinking in going already?
that was fast
 
Short of places that the state department has travel advisories against, I can't think of a country I wouldn't visit.
Except of course I'm lazy
 
3:23 PM
@billinkc what does it say about chile?
 
travel.state.gov/content/passports/en/alertswarnings.html Beware men with kiss marks on their cheek
Especially square mouthed robot kisses
Minefields are found in Chile's northern border region with Peru and Bolivia and around the southern border with Argentina in Patagonia. Minefields are generally marked, but markers may have shifted or may not be visible. Follow clearly identified roads and trails when traveling in minefield areas.
 
@billinkc now, that wouldn't be something to say about the wife
@billinkc don't worry, I can guide you
 
right into the mine fields
 
@billinkc I thought that you already walked into one, and that was the reason for that head
 
Why does this say "campo de la muerte?" Oh, it's uhh camps for hot moms, you gotta check it out
 
3:30 PM
sounds right
 
bye
 
unfortunately, no minefields in santiago
@AndyK you are a really polite person, that likes to say bye
 
@Lamak you two could possibly set up one
 
yup, that's an alternative
 
I could spend some time in Iquique, BTW
and that's unrelated to minefields
 
3:38 PM
@dezso really?, why?
 
@Lamak for paragliding reasons
 
I see
 
4:10 PM
What do you have already? Where are you stuck with the solution? — dezso 12 secs ago
me playing naïve
 
@dezso The community asking standard questions more like
 
@AndriyM but they apparently don't know that, otherwise they would have tried something before asking
 
4:44 PM
If you showed the code you already have, it would be easier to understand your problem... — dezso 19 secs ago
dentistry
 
4:59 PM
I think I understand what they are trying to do only I'm not sure if this can be done in PG without a cursor.
They essentially need to create a mapping between IDs from the source and those generated during the insert, so that the inserted IDs could then be updated in the source table.
 
5:30 PM
@bluefeet are you around? i have a question about phoenix. we were originally slated to go to SC for a fun fall break, but hurricane matthew has changed our plans. we're thinking about going back to phoenix because we enjoyed it so much. we're looking at north scottsdale and then this other place (the clarendon hotel?) in what looks like north-ish phoenix. can you tell me about fun/thoughts/recommendations regarding these locations?
 
JNK
SC would still be EXCITING
 
if not unavailable due to evacuations.
 
@swasheck Both are nice areas. The Clarendon is a great hotel that's located a bit closer to downtown phoenix - you're nearish the light-rail which can take you to some cool restaurants. But you've got kids so it sort of depends on what you want to do.
 
JNK
yeah heard they are trying to clear coasts
I have family down there
 
@bluefeet no idea. that's the rub. the other place (McCormick Ranch?) looks to have a better pool and is in scottsdale (with which we're familiar). it seems nice, but is also a bit limited. we like the funky boutique places as well (really enjoyed firesky) so the clarendon looks great and offers snacks, wine hour, etc., but the pool is limited.
so we dont know what we'd do with the kids
 
5:41 PM
@swasheck The clarendon is a nice place but I'm not so sure how it would be with kids. McCormick Ranch is a good location in Scottsdale - they just opened a new aquarium near by
Based on my knowledge of the clarendon it is more of a hipster type of place (or used to be), nothing wrong with that but I'm not sure how it'd be with kids
 
cool. thanks a lot, i really appreciate it. i was hipster before hipsters were cool
 
Not sure how helpful I was, but enjoy :)
 
quite
@bluefeet would you have any other phoenix/scottsdale recommendations?
 
5:59 PM
@swasheck hmm, do you want to just hang out and relax or go do stuff?
 
mostly hang out and relax
@bluefeet i think this is a "get away from everything and relax" sort of trip
 
There are some nice resorts near Camelback mountain (which is still close to old town scottsdale) - Scottsdale Camelback Resort. I think it's reasonably priced
McCormick Ranch area is nice though as well.
Pretty much anywhere in Scottsdale will be nice
 
thanks
 
JNK
6:24 PM
Wow the camelback resort is verrrrry reasonable
$237 a night for 2 bedroom villa??
 
6:36 PM
I keep on reading things about Data Scientists, and seeing job openings for them. Looking at what they do, isn't it us, with a splash of R?
It's what we do, day in, day out.
(As long as it's not ntext)
 
JNK
I think data science is more pure math and statistics focused
I could write you a kickass query but I'm not sure I'd be qualified to do in depth analysis on value distributions and such
 
6:55 PM
@JNK sounds ok.
If you have 7 children
 
JNK
7:10 PM
if you have 7 kids nothing is ever ok
 
7:24 PM
Additionally, never solve such issues with dropping a DISTINCT in there. These are usually results of wrong join conditions. And why do you need r.book_id in the output? — dezso 4 hours ago
@dezso in this case, the DISTINCT might just be the easiest way to solve the issue and get correct results.
Probably not the most efficient but still, never say never ;)
 
@Phil that's kinda the gist of it
 
@Phil No that's where you are wrong
They don't do what we do, they don't do much except talk
:32763001 huh?
 
I'm drunk
well, not really, since I don't drink
 
Maybe you should :)
Drink I mean, not the (removed)
 
yeah, maybe, I'm not cut out to be sober
 
7:43 PM
Heh
Well, we drink and do data, all agreed on that?
 
@Phil yeah. Perhaps that's where the data Scientists differ.They only do Data.
 
@ypercubeᵀᴹ yes, might be so. However, by the time of writing, there was no data available, and in my developer time I had inly a handful DISTINCTs in a largish codebase
 
@lamak having a good night?
 
it isn't even night yet
 
@TomV really?
 
7:54 PM
@bluefeet Just kidding mostly
Some people however have the skill to say "yes I know X" at a job interview while others would say "I know what it is but I don't have the audacity to claim I know it" and those are often the ones ending up with fancy job titles
 
8:15 PM
@TomV the 1st guys or the 2nd?
Is that a typo in Query 4? WHERE ... and PurchasedOn<getdate())viwHolderEvents ) Oh, never mind. It's jut wonderfully formatted ;) — ypercubeᵀᴹ 36 mins ago
(replace wonderfully with whatever you like)
 
JNK
@ypercubeᵀᴹ we have some subcontractors who do reporting work and when I have to look at their code it's very similar to that
one query will have 4 different alias patterns
'a' = 1, 2 as 'b', 3 c, 4 [d]
 
8:31 PM
@JNK Wow!
 
JNK
yeah
 
Code review: patch rejected
Reason: Unformatted SQL code
 
JNK
yeah I don't review their code for the most part
they can't touch anything that's really problematic
 
Famous last words.
 
JNK
true!
But they are 3 layers removed from anything transactional
they can see a datamart built off a clone of a transactional system
so 2 layers really I guess
 
 
3 hours later…
11:40 PM
Hello!
 

« first day (2102 days earlier)      last day (2767 days later) »