sona11

sona11

Declaring length in sql server

I want to declare max of length in case condition i.e 7 but getting a syntax error near select in this code.

DECLARE @SQ Int(MAX) 
SELECT @SQ= MAX(LEN(FIRST_NAME))  FROM #table
SELECT @SQ 
-- 7

DROP TABLE #T
SELECT CASE WHEN LEN(SEQ_NUM) = 0 THEN NULL ELSE SEQ_NUM END AS REC_NUM,
CASE WHEN LEN(FIRST_NAME) = 0 THEN NULL ELSE CONVERT(CHAR(SELECT @SQ= MAX(LEN(FIRST_NAME)) 
 FROM #table),RTRIM(UPPER(FIRST_NAME))) END AS FIRST_NAME
 INTO #T
FROM #table

--== Need  7 Char(7) -- Max of len
DROP TABLE #T
SELECT CASE WHEN LEN(SEQ_NUM) = 0 THEN NULL ELSE SEQ_NUM END AS REC_NUM,
CASE WHEN LEN(FIRST_NAME) = 0 THEN NULL ELSE CONVERT(CHAR(7),RTRIM(UPPER(FIRST_NAME))) END AS FIRST_NAME
 INTO #T
FROM #table

I tried figuring it out and also went through this resource that has similar things but was still unable to find the solution. Can anyone help me out in finding the solution? Thank you.

Popular General Dev topics Top

New
New
AstonJ
Please share your favourite Vim tips here :nerd_face:
New
AstonJ
Inspired by some of the comments in our https://forum.devtalk.com/t/your-vim-tips/4748 (in particular those by Mafinar and Hallski) …what...
New
ankur
Disassembly support, similar to what is there in Visual Studio, would be a great feature to have for low level programming (C, C++), and ...
New
CommunityNews
https://vimgifs-544mvq4w0-mraza007.vercel.app/ This thread was posted by one of our members via one of our news source trackers.
New
CommunityNews
I was a rather puzzled the first time I spotted DWIM in an Emacs interactive command name. Don’t think I remember what the command itself...
New
nirg
So, I actually got my Onivim License Key a while back. Am a Vim user for about 4 years. For me it was never ready enough for getting ac...
New
First poster: bot
Why? Why create Slate? Well… (Beware: this section has a few of my opinions!) Before creating Slate, I tried a lot of the other rich tex...
New
First poster: bot
Vim 9.0 released After many years of gradual improvement Vim now takes a big step with a major release. Besides many small additions the ...
New

Other popular topics Top

Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New
New
OSZAR »