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.

Where Next?

Popular General Dev topics Top

AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
First poster: bot
Why I Teach vim. The why of why people use vim has been covered fairly extensively, so I thought I would spend a little time explaining ...
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
Goodwill Strikes Again A symptom of heavy Vim usage is that your brain begins to re-partition old memories for keyboard shortcuts— trashi...
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
XSukhpreet
I think for now VsCode is getting very much goody at developer side, even thou sublime text 4 is faster . But if Onivim take these two an...
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
DevotionGeo
I installed Github Copilot (VS Code extension) and signed up for the technical preview three days ago. Yesterday I got the invitation, an...
New
First poster: bot
Modal editor · Faster as in fewer keystrokes · Multiple selections · Orthogonal design
New
malloryerik
I’m trying it out tonight. Any tips or experiences? I’ve actually had quite a bit of success with chatting with GPT-4, at least until it...
New

Other popular topics Top

axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
Or looking forward to? :nerd_face:
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
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
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New