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

AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
First poster: bot
Batteries included with Emacs. Emacs has a reputation for being borderline unusable out of the box, of being bloated but somehow surpris...
New
First poster: bot
What you need to know before try Emacs. When it comes to Emacs, every programmer should have heard its name more or less. After all, Ema...
New
AstonJ
Please share your favourite Vim tips here :nerd_face:
New
New
First poster: bot
Welcome to the second part of this series aimed to make you a better Vim user! If you have no idea about Vim, you should begin with the f...
New
First poster: bot
Download and play .puz crossword puzzles in Emacs. Includes a browser to view puzzles’ detailed metadata, including progress of partially...
New
First poster: iPaul
TL;DR: You want to teach yourself vim (the best text editor known to human kind) in the fastest way possible. This is my way of doing it....
New
First poster: OvermindDL1
It’s Magit! A Git interface inside Emacs Magit is a text-based Git user interface that puts an unmatched focus on streamlining workflows....
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

malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
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
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
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
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
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
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
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New