5

T sql concatenates the column name and string

 3 years ago
source link: https://www.codesd.com/item/t-sql-concatenates-the-column-name-and-string.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

T sql concatenates the column name and string

advertisements

I am using a Case statement within a SELECT query to return a concatenated string. The string I want to return is a concatenation of a column value and a string specified within the query.

I have pasted the code below, the concatenation part (bold) is shown as if it was in Excel. Please instruct on how this would be done in T SQL.

WHEN (InstrumentType = 'Loan' OR InstrumentType = 'LoanF') AND Leg.Principal <0
THEN CONCATENATE(InstrumentType,' Deposit')


IN SQL Server 2008 something like this should work:

SELECT
    CASE WHEN InstrumentType IN ('Loan','LoanF') AND Leg.Principal < 0
        THEN InstrumentType + ' Deposit'
        ELSE 'somethingelse'
    END AS YourColumn
FROM dbo.Yourtable

Related Articles

Caused by: java.sql.SQLException: The column name is specified multiple times in the SET clause

I am facing a below issue while persisting data to a table. Error : Caused by: java.sql.SQLException: The column name 'SubFundId' is specified more than once in the SET clause. A column cannot be assigned more than one value in the same SET clause. M

Yii2 prints the column name and its value using the loop

I'm trying to print the column name and it's value of a table using foreach loop of each column in my table. I want this code $contentAfter = DepCustomer::findOne($id); echo $contentAfter->customer_id; echo $contentAfter->account_no; echo $contentAf

Get the value of the column from the column name of string sql

Is this possible to get multiple columns value when we have column name as string Like if i have a table Test and i have columns FirstName , LastName , Address . Now what i want to get value of all three columns but i want to make this dynamic so tha

SQL: Combine the First Name and Last Name columns, but if Null becomes "Name not provided"

I'm currently building a simple view and need to combine both the First Name and Last Name columns to create a new Customer column. If a First Name and Last Name are not provided I'd like to change this new combined value to 'Name Not Provided'. Curr

How do I display a row in the rows in which each row contains the column name and the other indicates the value?

I have a table that contain about 60 columns and if i write a select query in query analyser to get a row it show it and i must scroll to show data .. How can i get one row in which it shows as 60 row, each row contain 2 columns one for column name a

Change the column name by string ID in the name of the old column

Consider I have a data frame in R with the col names: data: A B C D E V1 V2 V3 V4 V5 V6 Vx... 2 3 4 5 6 5 5 5 5 2 2 how could I grab all values that contain a V and replace it with Sample so I get: data: A B C D E Sample1 Sample2 Sample3 Sample4 Samp

PHP / mySQL gets all the column names and creates a list

I'm using this to define the valid keys that can be used to perform a search on my front end: $validKeys = array('gender','marital_status', 'age'); The rest of my code works great in that it only accepts keys sent to it in an AJAX call that are in th

How can I run a query when the column name and table name are passed?

Given a table name and column name in a pair of variables, can I perform a select query without using dynamic sql? for example, I'd like something nicer than this: CREATE PROCEDURE spTest (@table NVARCHAR(30), @column NVARCHAR(30)) AS DECLARE @sql NV

Replace the values ​​of the cell in the data frame according to the column name and the variable match

I would like to replace the value in a data frame cell based on the column name matching a row variable, as in the example code. I know enough to know that the nested loop is not the preferred way to do this (and that a more efficient solution is pro

Get the column names and values ​​of the SQL query as a row

In my database i have a table (SqlQueries) with columns (ID, SQLText), in which are stored values ID SQLText 1 SELECT FIELD1 as FD1, FiELD2 as FD2 FROM TABLE1; 2 SELECT FIELD3 as FD3, FiELD4 as FD4 FROM TABLE2; For some reasons, i am using in my stor

Concatenate the file name and file path, the path is split?

I have a program, that expects a file path and a part of the file name as input. #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> char filename[3][50]; void main(int argc, char **argv) { int run; run=ato

Extract the column name and the specific value according to a condition

Suppose that I have the following data frame: firstname <- c('Doug','Tom','Glenn','Billy','Angelo') city <- c('Tulsa','Unknown','Miami','Houston','Unknown') state <- c('OK','CA','FL','Unknown','Unknown') job <- c('Unknown','Plumber','Professor

In Python (Pandas-Numpy), how can you change the column names (strings), using a condition and an iteration?

I'm trying to modify the column names of a dataframe with a lot of columns. The column names are strings like: '0000', '0005'...'0100'...'2355' Since is a large amount of columns, I need to do this with iteration. The gist of the modification is that

Newb SQL question: is there a & ldquo; Foreign key & rdquo; Equivalent for referencing columns, or is it logical to store column names as strings in another table?

Disclaimer: I'm an SQL newb, just discovering the great possibilities of sqlite embedded in applications. I'm designing a small database for an application that primarily handles data storage for plotting. Say I have several instrument data tables (o

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK