where clause requiring double quotes on an nvarchar? - double

all columns in DataImport table are nvarchar(max). column d is requiring double quotes.
the statement:
select cast(i.a as varchar(50)) as address,cast(i.c as varchar(50)) as phone
from dataimport i where i.d="x"
produces two records.
the statement:
select cast(i.a as varchar(50)) as address,cast(i.c as varchar(50)) as phone
from dataimport i where i.d='x'
produces no records
column definition is d(nvarchar(max),null)

Is there a column called x?
Using double quotes you're specifying column names and not data inside a column.
If the statement is not returning any data using single quotes there seems to be no record containing a 'x' inside column d.

Related

Can a string array parameter be inserted into a table [variable] defined in the command of the report?

I have an array parameter that I need to represent column names for a report. I have a command that queries the database for data and pivots it. I wanted to pass in the columns. The part I am having trouble with is adding the parameter values to the temp table that holds the column names.
This example does not work but I am hoping it gives an idea what I am after
So, the ?Fields parameter is my array....
Thanks!!
-- test parameters
declare #tab table(field
varchar(100))
-- insert into #tab values('John'),
-- ('Sarah'),('George')
insert into #tab
VALUES ({?Fields})
SELECT * FROM #tab

postgres: apply aggregate function to column with spaces in name

I am trying to run a query like this
SELECT group, sum("a column with spaces") FROM x GROUP BY group
Unfortunately, I get the error function sum(text) does not exist. It appears to be interpreting my quoted identifier "a column with spaces" as a text string instead of column name. How can I specify that this is an identifier?
I found a way to trick it into parsing it as an identifier -- prefix it with the table identifier or alias:
SELECT group, sum(t."a column with spaces") FROM table_name t GROUP BY group;
Double-quotes are actually the right way to identify columns, but in this case it won't work.
I managed to apply an aggregate function renaming the column and removing its white spaces.
CREATE TABLE example (
"column with space" INTEGER
);
INSERT INTO example VALUES (1), (2);
SELECT SUM(column_with_space)
FROM (
SELECT "column with space" AS column_with_space
FROM example
) AS example_query;
Got result:
sum
3

search string and insert value in table

i have table having below records.The below product description are given by user in textbox in
front end(asp.net).The product description will come with single quotes or double quotes.i want to insert in the table.so how can we check whether single quotes or double quotes are exists in the
the input and insert value in the table.please help.
String s=Textbook
CREATE TABLE Product_Details(Product_Description varchar(50))
Required Output
Product_Description
-------------------
STORE('COVERED)
STEEL("ROOFED)
Insert statement will be differ for above two string?.
I'm not sure what exactly what you are looking for. You should be able to store text with quotes or double quotes without any trouble (note, I'm testing on Postgresql 9.4, don't have 9.2).
The problem is sometimes creating the text with the single quotes. In those cases it is common to have two single quotes like this insert into product_details values ('STORE(''COVERED)') The double quotes (") should not be a problem. You can use the syntax E'STORE(\'COVERED)' instead of the two quotes. Sometimes more readable.
If you just want to check if there are ' or "" in the input, this check is convenient:
select length(replace(product_description,'''',''))!=length(product_description),
length(replace(product_description,'"',''))!=length(product_description)
which return true/false columns telling if single-quote exists in string in first column and double-quote in the latter.
To delete the quotes in string you can do:
select replace(replace(product_description,'"',''),'''','')
Best regards,
Bjarni

export records from a table by modifying without double quotes for the numeric columns from the table in db2(udb)

I am trying to remove the double quotes for the numeric columns using export command by using replace function but it wont worked out, below is the query I used in Linux environment,
EXPORT TO '/Staging/ebi/src/CLP/legal_bill_charge_adjustment11.csv' OF DEL
MESSAGES '/Staging/ebi/src/CLP/legal_bill_charge_adjustment11.log'
select
CLIENT_ID,
CLIENT_DIVISION_ID,
CLIENT_OFFICE_ID,
MATTER_ID,
LEGAL_BILL_CHARGE_ADJ_ID,
LEGAL_BILL_CHARGE_ID,
ADJUSTMENT_DT,
replace ( ORIGINAL_ADJUSTMENT_AMT,""),
replace (CURRENT_ADJUSTMENT_AMT,""),
replace (SYSTEM_ADJUSTMENT_AMT,""),
replace (CLIENT_ADJUSTMENT_AMT,""),
replace (DELETED_ADJUSTMENT,""),
FLAGGED_AMOUNT,
ADJUSTMENT_USER,
STATUS_DESC,
ADJUSTMENT_COMMENT,
WF_TASK_NAME,
WF_TASK_DESC from CLP.legal_bill_charge_adjustment1;
If anyone suggest me the exact db2 query it would be helpful.
Thanks in advance.
Export will not have quotes around numeric data types. You have not provided any data type information so I suppose your numeric content may be stored in a CHAR/VARCHAR column.
Try casting the columns to numeric data types in the export SQL statement.
i.e.
SELECT cast(Textcol as integer) as colname
..

How to reduce multiple insert into in postgresql?

is it possible to reduce a multiple insert into in PostgreSQL.
i have this:
insert into table (id,name,city)
values ('1','Mike','Orleans')
insert into table (id,name,city)
values ('2','Paul','Paris')
so i have to insert more than 100 datas.
Can we do it in one query
Thank you
insert into the_table (id,name,city)
values
(1,'Mike','Orleans'),
(2,'Paul','Paris');
If id is an integer column, then don't provide a string value for it. '1' is a string (character) value. Numbers are specified without single quotes: 1 is a number.