« first day (1875 days earlier)      last day (1305 days later) » 
00:00 - 19:0019:00 - 00:00

7:07 PM
something like @this:
	BEGIN TRY
		SET @result = CAST(@workSSN as int)
	END TRY
	BEGIN CATCH
		SET @result = 0;
		THROW 50042, CONCAT(N'Non numeric SSN provided: ', @workSSN)
		RETURN (-1)
	END CATCH
the RETURN (-1) is superfluous though, isn't it?
 
well I do put it in though, and also at end, too.
 
Never gets there because of the THROW
 
yep
but fwiw....
 
just for completeness/OCD sake
 
BEGIN TRY
   --do work

   IF myCondition = 0
   BEGIN
     SET @errMessage = N'derp';
     THROW 50001, @errMessage, 1;
  END;

   IF myOtherCondition = 0
   BEGIN
     SET @errMessage = N'duh';
     THROW 50002, @errMessage, 1;
  END;

END TRY BEGIN CATCH
   SET @errNumber = ERROR_NUMBER();
   THROW;
   RETURN @errNumber;
END CATCH;

RETURN 0;
note: aircode. Caveat emptor
also, note the use of semicolons. ;)
 
7:15 PM
what does the unparameterd THROW at the end do?, just returns whatever err number caused it to end up in the CATCH?
 
yeah
 
yeah... not good with remembering the semi-colon
 
Rethrows the same error, likely.
 
that only works in the CATCH block, though.
 
Note that if there's a stack trace, it probably doesn't reset that either.
 
7:16 PM
Note this:
> The statement before the THROW statement must be followed by the semicolon (;) statement terminator.
 
Or whatever SQL does with throws.
 
Your code is effectively what I've done, I just didn't wrap the whole thing in a TRY...CATCH (yet. :)
 
so this will be .... surprising:
 
(is it not?)
 
7:17 PM
BEGIN
  THROW 50001, N'doesn't throw....', 1
END
this is a syntax error. Yay!
@FreeMan I was concerned you were using it for each statement. Mine shows you only need only one TRY/CATCH block
 
just using it to validate that I've got only numbers in the SSN field at that point.
 
ok. just don't want to do it the SQL Server 2000 way. :)
 
12345678a isn't really a valid SSN anywhere I'm familiar with...
not sure what that way is, but it sounds bad.
 
OTOH, I usually have my guard clauses return before I enter the TRY block furhter down.
basically storing the @@ERROR into a local variable, checking that it's 0 before proceeding further. SO MUCH FUN.
 
@this BEGIN; <~ wtf
 
7:23 PM
@this but sometimes I end up needing guard clauses inside since it can only be validated after some DML statement has executed. the TRY basically should contain all the DML statements, obviously and I usually have a transaction if it's crucial DML.
@MathieuGuindon IKR? Such is the joy of T-SQL.
that's why I "work around" it by setting a local variable even if I actually don't need it:
BEGIN
  SET @errMessage = "derp';
  THROW 50001, @errMessage, 1;
END;
T-SQL's consistency is right up there with VBA and JS, unfortunately.
 
tSQL, VBA, both from MS, so their inconsistency is consistent...
@this ahhhh! that makes so much more sense
 
apparently begin is an instruction that warrants a semicolon. I ...I just can't.
@this better than ;throw
 
@MathieuGuindon Neither can I. it's just mind-bending.
But the parser is kind of dumb - BEGIN THROW get interpreted as a marker for transaction scope because THROW wasn't originally a reserved keyword. :\
@MathieuGuindon unfortunately I see a number of people electing this options, esp. with CTEs..... #ContributingToProblem
 
7:40 PM
Guess it would make sense to extract the SSN cleanup/validate procedure to its own stored proc, then it could be tested on its own (pass a variety of potential SSNs, make sure I get the right thing back), then used to validate the SSN I'm using in other stored procs.
(clean-up includes removing -, ., ` ` from it so I've got just digits left)
is there an easy way to REPLACE(@mySSN, [A-Z,a-z], '') ?
 
hm, if it has alpha, it's not a SSN?
 
not as far as I know!
 
so why are you stripping alpha?
 
3 hours ago, by Hosch250
In the United States, a Social Security number (SSN) is a nine-digit number issued to U.S. citizens, permanent residents, and temporary (working) residents under section 205(c)(2) of the Social Security Act, codified as 42 U.S.C. § 405(c)(2). The number is issued to an individual by the Social Security Administration, an independent agency of the United States government. Although its primary purpose is to track individuals for Social Security purposes, the Social Security number has become a de facto national identification number for taxation and other purposes.A Social Security number may be...
@this so if I get 123-45-678a I can spit it out as an invalid SSN instead of looking for a person with that "number"
 
but you're doing REPLACE(..., '[A-z]', '')
why not: IF NOT @ssn LIKE '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]' .... ?
(not sure if the - needs to be escaped)
 
7:47 PM
A) Can I do that? B) Once I've replaced any letters, it will fail the LEN(@mySSN) = 9 test
 
you don't even need the LEN test....
 
@this no way to get \d{3}-\d{2}-\d{4}?
 
it must conform to the format of xxx-xx-xxxx
hmm. that's regex, isn't it?
LIKE isn't regex
 
that's why I'm asking ...
 
most of the files I get don't have dashes, so I'm not storing with them, but the regex description is otherwise correct
 
7:48 PM
in that case, you can handle both dash format and non-dash format
but they must match one of either.
otherwise you have a no-go
 
Yeah, except sometimes I use a . separator because it's easier to type on the Num keys than a - (and I can be a jerk to the programmers). Don't think I'd ever need to manually input SSNs to search, but, if I do...
picture forming...
 
fwiw, i usually prefer to strip away all formatting
always easiest to store only the raw data in database. you can then format it anyway you please.
 
yup
whew!
	DECLARE @workSSN nvarchar(11);
	SELECT @workSSN = REPLACE(@searchSSN, '-', '');
	SELECT @workSSN = REPLACE(@workSSN, '.', '');
	SELECT @workSSN = REPLACE(@workSSN, ' ', '');
	SELECT @workSSN = REPLACE(@workSSN, '[A-Z,a-z]', '');
	SELECT @workSSN = TRIM(@workSSN);

	IF @workSSN NOT LIKE('[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
	BEGIN
		SET @result = 0;
		SET @errMessage = CONCAT(N'Incorrect SSN format provided: ', @workSSN);
		THROW 50042, @errMessage, 1;
		RETURN (-1);
	END
	SET @workSSN = CAST(@workSSN as int);
Sadly, SELECT @workSSN = REPLACE(@workSSN, '[A-Z,a-z,[-],[.],[ ]]', ''); doesn't work.
 
8:04 PM
confused you're still stripping alpha and whatever....
 
since I need to work with a 9-digit SSN, it only makes sense to strip the dashes. Guess it's not necessary to strip letters since it won't match the [0-9]^9 pattern...
but... I'm just validating that I've got an otherwise all numeric SSN... so stripping those characters at this point would be side affecting if I was actually returning the edited SSN, so nevermind...
blarg
 
I would only strip the - and maybe . and ` `, that's it.
if it has anything else and doesn't meet hte format of 9 digits, you lose, thanks for playing!
 
Yeah, but this isn't... well, actually it is... returning the stripped SSN. Actually it isn't but it easily could and probably should...
CREATE PROCEDURE [dbo].[CleanUpSSN] (
	  @searchSSN nvarchar(11),
	  @validSSN int out)

AS
BEGIN

	DECLARE @workSSN nvarchar(11);
	SELECT @workSSN = REPLACE(@searchSSN, '-', '');
	SELECT @workSSN = REPLACE(@workSSN, '.', '');
	SELECT @workSSN = REPLACE(@workSSN, ' ', '');
	SELECT @workSSN = TRIM(@workSSN);

	IF @workSSN NOT LIKE('[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
	BEGIN
		DECLARE @errMessage nvarchar(255);
		SET @errMessage = CONCAT(N'Incorrect SSN format provided: ', @searchSSN);
Actually, @validSSN should be @validatedSSN #namingishard
and @searchSSN should be something like @inputSSN
 
8:20 PM
ok one more question. Why isn't this a scalar function?
i see no reason for it to not be one.
 
@this do you use the incredibly painfully long tSQLt naming convention: CREATE PROCEDURE testFinancialApp.[test that ConvertCurrency converts using given conversion rate] or do you suck all the spaces out of that [] phrase?
ummm... cause I didn't think of it.
if I go with a scalar function, I either get a @validatedSSN or an error, right?
CREATE OR ALTER FUNCTION [dbo].[CleanUpSSN] (
	  @inputSSN nvarchar(50))
RETURNS nvarchar(9)
AS
BEGIN

	DECLARE @workSSN nvarchar(50);
	SELECT @workSSN = REPLACE(@inputSSN, '-', '');
	SELECT @workSSN = REPLACE(@workSSN, '.', '');
	SELECT @workSSN = REPLACE(@workSSN, ' ', '');
	SELECT @workSSN = TRIM(@workSSN);

	IF @workSSN NOT LIKE('[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
		RETURN (-1);

	RETURN @workSSN;

END
allow nvarchar(50) in order to return -1 if I pass in 123-45-6789a.
Though... declaring it as nvarchar(11) nicely takes care of that automatically...
but, I don't think that's the way I want to handle it.
OK, lots of SELECT dbo.CleanUpSSN '<something.' tests run, now to write 'em up formally in tSQLt.
Thanks again for the patience, @this!
Yay!!!
(0 rows affected)
[testFindBySSN].[testSsnTooLong] failed: (Failure) Expected actual value to not equal <123456789>.

+----------------------+
|Test Execution Summary|
+----------------------+

|No|Test Case Name                     |Dur(ms)|Result |
+--+-----------------------------------+-------+-------+
|1 |[testFindBySSN].[testSsnWithDash]  |      0|Success|
|2 |[testFindBySSN].[testSsnWithLetter]|      0|Success|
|3 |[testFindBySSN].[testSsnWithPeriod]|      0|Success|
|4 |[testFindBySSN].[testSsnWithSpace] |      0|Success|
(yeah, I know one failed... I'm excited that I've got some tests setup and they ran!)
Now to start doing this in mah VBA code!!!
 
8:44 PM
nice job.
just as a reminder - they like to suggest that you write failing test first
but TBH I'm not always good at that because sometimes I find the design too much in flux so it's not easy to write a failing test before there's an implementation
but the reasoning is to prove that the test itself is working
@FreeMan Yes. One more thing - you always should have a WITH SCHEMABINDING on your scalar function. That helps the optimizer know that there is in fact no data access for the scalar function and do a better job for optimizing the calls to the function.
Actually, I wouldn't do RETURN (-1); but rather RETURN NULL; if you prefer to not throw an error. If you want it to throw an error, I think you can do a THROW right there in the function, with the message. Your VBA code then needs error handling.
 
I tried THROW in the Function and it didn't like that.
 
whether it's appropriate to return NULL for non-valid values is a subject of debate.
 
Guess I could change it to return NULL
 
Ok, yeah, functions has some rules preventing it from having side effects.
so I'd have used NULL, yeah.
 
makes sense to @validatedSSN = CleanUpSSN ... IF @validatedSSN IS NOT NULL ...
tomorrow.
TTQW on a high note!!
@this BTW - I'm patting myself on the back for writing a test!!! never mind what "they" say! :D
 
8:54 PM
agreed!
 
having an @IvenBachâ„¢ moment here...
2
 
9:05 PM
^+1
 
9:18 PM
Sigh.... lovely working conditioms today as well...
I opened three tabs while building the app and now my PC is locked up since 5 minutes
Whatever...
 
9:34 PM
sounds like a FTS moment
in other news... its going to be 107°F on sat, and 110°F on sunday in my town
<<is the sad
 
@KySoto yea, it's also close enough to midnight to really say that
 
oof
 
I only started working on it at 8PM, soo ...
I'm really shifted around with my sleep cycle rn...
 
yeah, sounds.. uhh
not the best
well, if you wanna be able to do stuff when business' are open
 
oh it's okay, so long as I'm still a student
and I usually wake up around noon
 
9:40 PM
i was a night owl too
 
 
1 hour later…
10:58 PM
 
11:33 PM
0
Q: "String Interpolation in {language}", "VBA"

Robert Todar"This is {0} cool!", "freaking" I've always wanted an easy and intuitive way to inject variables into a string. So after about 10 variations, I finally came up with this function. How it works The concept is that I can find every pattern such as {key} or {0} or whatever {taco} and get a uniq...

 
00:00 - 19:0019:00 - 00:00

« first day (1875 days earlier)      last day (1305 days later) »