What is this trying to do: Convert(CHAR(7), @End_Date , 120)

I found it in an old BAQ, but I’m not sure what the CHAR(7) is meant to do here.
the @End_Date is a date parameter.
I have not ever used the Convert() function of BAQs, any Convert or Cast I’m used to is just Convert(thing to target data type) format

Thank you.

Looks to be a date format.

SQL Server CONVERT() Function (w3schools.com)

Although ,converting to CHAR(7) is interesting…

(computing) A control character with the value seven (Unicode code point U+0007, ASCII 0x07), originally used to ring a bell on telegraphy equipment to alert the operator to an incoming message; on modern computers, generally causes a beep or buzzer to sound when printed to a terminal window, or may cause the terminal window to flash briefly.

1 Like

Convert() in the BAQ is still the SQL Convert() function you mention.

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

Looks to be converting a date value to a 7 character text field using the style # 120 which doesn’t seem like it would work but SQL might truncate accordingly. Most folks use this to strip off the “time” element of a datetime field.

I think it works more simply if you just cast(@End_date as date) instead of the Convert() syntax, but everyone has their own way.

Style 20 or 120 - ODBC canonical yyyy-mm-dd hh:mi:ss (24hr)

CAST and CONVERT (Transact-SQL) - SQL Server | Microsoft Learn

2 Likes

You beat me by a minute!

LOL - I thought that too, but if this is an OLD BAQ, then CHAR is the field type and length. We’re so used to nvarchar or varchar now, we forget about the old ones.

1 Like

I think it would be WAY more fun if it converted the dates to beep codes. :sweat_smile:

This seems odd to me considering a date field is 4+ characters. At minimum, 4 for a style of 4522 (April 5th, 2022 – confusing, but technically legit). I can’t think of one for 7. I have one for 6 at 4-5-22 or 8 at 4-5-2022 (or variations of 4522 / 040522 / 04052022 / 04-05-22 / etc). I guess you could have 7 at 4-05-22, but that’s only relevant for a certain subset of dates.

I believe @hmwillett is correct… this CHAR(7) function returns the ascii value for Bell, which by the way… is a very mean trick you can do on an old teletype machine where you could make a paper tape punch of the ascii 7 a bunch of times, and create a loop of the paper tape and turn on the paper tape reader just as you are leaving the classroom (dont ask me how i know this.) Teletype ASR 33 Part 10: ASR 33 demo. - YouTube

Here is a link to an article about CHAR in SQL:

2 Likes

Bells would be fun!

I agree - but I believe SQL will truncate, and if that’s the case, combined with the Style code, it would return ‘2022-11’ for today - meaning they were just going for the year/month, or period of the transaction.

1 Like

Ahhh, thank you. That was bugging me, lol.

It does, or it used too! I wonder if it still will???

In this case, in conjunction with Convert() it’s would be used like this:
char and varchar (Transact-SQL) - SQL Server | Microsoft Learn

1 Like

Thank you all for the information and interesting posts.