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.

First Post!

bot

bot

Corresponding tweet for this thread:

Share link for this tweet.

Popular General Dev topics Top

New
New
ankur
I am thinking of switching to Onivim from VSCode Vim since VSCode Vim supports limited Vim features . Would like to hear from the current...
New
First poster: bot
Feature Packed Everything you need to get started without any configuration. A completely usable editor, right out of the box. Text-base...
New
First poster: bot
This article is the fifth of the series aimed to teach Vim from the ground up: Vim from the ground up Vim for Beginners Vim for Interm...
New
First poster: KnowledgeIsPower
Hi, it’s Takuya. I use Neovim to develop my app called Inkdrop. Recently, I’ve got some updates for my Neovim setup since I’ve published ...
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
CommunityNews
Neorg is a tool designed to reimagine organization as you know it. Neo - new, org - organization. Grab some coffee, start writing some no...
New
First poster: bot
Here’s my (current) minimal setup: set ai nocp digraph ek hid ru sc vb wmnu noeb noet nosol set bs=2 fo=cqrt ls=2 shm=at tw=72 ww=&l...
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

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
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
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
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
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New