how we can replace the multiple values in a single select statement? I have to build the output based on values stored in a table. Please see below the sample input and expected output.
I need to replace all the "User Friendly Names" with "System Names" in the calculations, i.e., I need "Sales Units" to be replaced with "cSalesUnits", "AUR" replaced with "cAUR", "Comp Sales Units" with "cCompSalesUnits", and "Comp AUR" with "cCompAUR". (It isn't always as easy as removing spaces and added 'c' to the beginning of the string...)
I have created a CTE of all the "Look-up" values, and have tried all kinds of joins, and other functions to achieve this, but so far nothing has quite worked.
How can I accomplish this?
Here is some SQL for set up. There are over 500 formulas that need updating with over 400 different "look up" possibilities, so hard coding something isn't really an option.
I want to be able to create a trigger that updates table 2 when a row is inserted into table 1. However I€™m not sure how to increment the ID in table 2 or to update only the row that has been inserted.
I want to be able to create a trigger so that when a row is inserted into table A by a specific user then the ID will appear in table B. Is it possible to find out the login id of the user inserting a row?
I believe the trigger should look something like this:
create trigger test_trigger on a for insert as insert into b(ID)
Can a Trigger be created to automatically replace NULL values with "-"? Suppose I have an Entry Form with 20 Text Boxes. I don't want to code in my application. I want that when an Insert Query is executed, a BEFORE/AFTER TRIGGER should be executed to replace the NULL values coming from Insert QUery to "-".
I also want to know whether to use a Trigger or a Function/Stored Procedure.
I need to separate the data from one column in to two columns based on the transaction type TRAN_TYPE (C is credit, D is Debit)
TRAN-TYPE| AMOUNT C 20.00 D 30.00 C 50.00
To do that I have this code:
select CASE WHEN TRAN_TYPE = 'D'THEN CAST (ISNULL(amount, 0) as varchar (30)) end as DEBIT, CASE WHEN TRAN_TYPE = 'c'THEN CAST (ISNULL(amount, 0) as varchar (30)) end as CREDIT FROM HISTORY
I AM HAVING A TABLE WHICH HAS INCREMENTAL COLUMNS,WHERE COLUMNS GETS ADDED EVERY MONTH TO THE TABLE AND THE TABLE THEN CONTAINS PREVIOUS MONTH AND PRESENT MONTH DATA ABOUT CUSTOMERS ,DETAILS AND TRANSACTIONS. THE PROBLEM WITH THIS DATA IS ,IF THE CUSTOMER IS NEW ,THEN IN PREVIOUS MONTHS HIS INFORMATION IS NULL,WHICH HAVE TO BE CODED HAS "NOT PRESENT".
NOW, HOW DO WE CONVERT ALL THE PREVIOUS COLUMNS FOR A PARTICULAR CUSTOMER HAS NULL AT THE SAME TIME ?.
HERE IS HOW THE PROC WRITTENED FOR IT GOES :-
DROP PROCEDURE DE_NAT CREATE PROCEDURE DE_NAT AS BEGIN DECLARE @MONMIN1 NVARCHAR(100),MON NVARCHAR(100),@YEAR NVARCHAR(100) , @MONYEAR NVARCHAR(100) SET @MONMIN1 = DATENAME((MONTH),DATEADD(MONTH,-1,GETDATE())) SET @MON = MONTH(GETDATE()) SET @YEAR = YEAR(GETDATE()) SET @MONYEAR = @MON + @YEAR
EXEC('select A.CUSTOMERS,B.*,CAST(A.RFM_40D AS FLOAT) AS R40 INTO TSD_' + @MONYEAR + ' from TSD_20 A LEFT OUTER JOIN SD20 ' + @MONMIN1 + ' B ON A.CUSTOMERS = B.CUSTOMER') END
THIS PROC JUST ADDS THE PRESENT MONTHS DATA TILL LAST MONTHS DATA.
BUT IF A CUSTOMER IS NEW, THEN HOW DO I REPLACE THE NULL VALUES FOR THE PREVIOUS DATA TO 'NOT PRESENT'
FOR EG :- IF THERE IS A NEW CUSTOMER ,HOW DO WE CHANGE :-
NOW, AS YOU CAN SEE, THAT FOR CUSTOMERS = '101023'. THE COLUMN DFGHHGFD IS, THIS MONTHS DATA , I WANT TO CHANGE ALL NULL VALUES PRESIDING IT AS "INACTIVE"
CAN I CHANGE , ALL COLUMNS FROM NULL TO "INACTIVE" , AT THE SAME TIME. ?
AS NEXT MONTH, AGAIN THE COLUMNS IS GONNA INCREASE WHICH WILL AGAIN CAUSE A PROBLEM .
PLS TELL ME A METHOD , SO THAT I CAN DO THE NEEDFUL.
how should i use replace function in sql statement??
in my scenario, user enters the meeting ID and i want that if user enters the meeting ID which includes apostrophe('), the stored procedure should remove the apostrophe before inserting it into database table.
my stored procedure accepts two parameters. Is there any way to solve my problem??
Field Name Type Size Key-------------------------------------------------- attr_name char 25 PK attr_value nvarchar 250 PK comment nvarchar 100
the records in the table are
attr_name attr_value comment------------------------------------------------------------------ mail dasari.kanth@gmail.com nothing mail xyz@gmail.com nothing UID test123 nothing -------------------------------------------------------------------- now i am trying to update this table with the below UPDATE command
update attribute_definitions set attr_value=replace(attr_value,'gmail','yahoo') where attr_name='mail'
but the above update statement giving the error like "Violation of PRIMARY KEY constraint 'PK_attribute_definitions'. Cannot insert duplicate key in object 'attribute_definitions'."
I've to translate this SQL-Statement from ORACLE to SQL-Server. But I'm missing the Minus-Statement on SQL-Server. select table_name, column_name from user_tab_columns where table_name not in ( select table_name from user_tab_columns minus select tab_name from data_dic ) minus select tab_name, col_name from data_dic what can I do to run it on SQL-Server. Thanks in advance Raimund
create table #task(TaskId bigint unique, Name varchar(2000)) insert into #task values(1, 'Text Text Text Text Text Text Text <<Name>> Â Text Text Text <<Salary>>') insert into #task values(2, 'Text Text Text <<Name>> Text Text Text Text <<Company>> Â Text Text Text <<Salary>> Â Text Text Text')
[Code] ....
Now I need to create an inline function who resolve the task name with appropriate values and return me the resolved task name
select * from fn_TaskResolver(1, 'Text Text Text Text Text Text Text <<Name>> Â Text Text Text <<Salary>>')
I try this function but its return multiple rows as i just want to return one row. as I have big data set so i don't want to use scaler or Multi Line function.
create function fn_TaskResolver(@TaskId bigint, @name varchar(2000) Return table as return
When I import my tables from MySQL, it put " " with the contents in the field. Will someone show me a SQL statement that I can use to clean all the " " out of the table's contents?
The string column value looks like as below. Each value has a size of 15 withing a string
'2.2020 30 4.0000'
The column value should match with user input as below. The result should show equal when it is compared. Currently, it results not equal since it is a string comparision. The last digit '0' needs to be ignored for decimal values.
'2.202 30 4.0'
I need to handle the decimal values in such a way, if staring value with '.' and last digit is 0 then replace with space ''. So, it should look like
'2 2 2 30 4 ' = '2 2 2 30 4 '
When this string is compared, it results in EQUAL.
I tried the below logic, which even replaces the integer value like 30 to 3 and 3000 to 3 and results in equal which is incorrect.
create table #task(TaskId bigint unique, Name varchar(2000)) insert into #task values(1, 'Text Text Text Text Text Text Text <<Name>> Text Text Text <<Salary>>') insert into #task values(2, 'Text Text Text <<Name>> Text Text Text Text <<Company>> Text Text Text <<Salary>> Text Text Text') -- select * from #task
[Code] ....
Now I need to create an inline function who resolve the task name with appropriate values and return me the resolved task name
select * from fn_TaskResolver(1, 'Text Text Text Text Text Text Text <<Name>> Text Text Text <<Salary>>')
I try this function but its return multiple rows as i just want to return one row. as I have big data set so i don't want to use scaler or Multi Line function.
create function fn_TaskResolver(@TaskId bigint, @name varchar(2000) Return table as return ( with data as
Running into a problem with trying to pull multiple values in a stored procedure. Ran Profiler for trace on what variable is coming back as when running in Reporting Services. Profiler shows this:
Trying to run Replace function but not quite getting the syntaxt correct. The stored procedure will work but when running report will often get unclosed quotation marks. What I have:
For example we've got a row from [Formula_Calc] table 'F1+F3' as a string that needs to be transformed as 240+160=400
The below code works for the above example but if I pick 'F11+F3' instead , returns 2561 which comes from 2401+16. Probably replaces F1 value instead of F11 and adds 1st digit (1) if I got it right ...
DECLARE @formula NVARCHAR(100); DECLARE @Total NVARCHAR(100); SET @formula = 'F11+F3';
SELECT @formula = REPLACE(@formula,RowNo,Total) FROM [Totals]
I need to update serverB.databaseB.tableB.columnB value based on serverA.databaseA.tableA.columnA value change,
the update trigger in serverA.tableA works fine in updating a testing databaseB.tableB.columnB in the same serverA.
serverB is as the linked server in ServerA and DTC is on. when change the trigger to point to serverB.databaseB.... error:-------------------------------------------- Server: Msg 7395, Level 16, State 2, Procedure trInsUpdDel_InboundCannedMessages, Line 169 Unable to start a nested transaction for OLE DB provider 'SQLOLEDB'. A nested transaction was required because the XACT_ABORT option was set to OFF. [OLE/DB provider returned message: Cannot start more transactions on this session.]
Hi All,I'm a relatively newbie to SQL Server 2000, having come from a MySQLbackground.I'm creating my first Trigger statement on a table, and I'd like toknow how I go about performing an update on the row that was changedwhen the trigger was fired.To explain, I have 2 columns, one which contains a member number, theother which contains a flag that is supposed to indicate whether ornot the member number in the row has changed since the last time thetable was processed for updates.So, whenever the value in the member number field [memnum] is updated,I want to set the flag [igproc] to true.The best I've been able to do is:CREATE TRIGGER [updateignoreprocflag] ON [dbo].[dd_testtable]FOR UPDATEASdeclare @key as intIF UPDATE (memnum)select @key = recid from insertedUPDATE dd_testtable set igproc=1 where recid=@keyThis seems to work, but I'd like to know if there's a better way ofretrieving the recid value of the changed row to pass to the UPDATEstatement? Also, I read somewhere in passing that using SELECTstatements and variable assignments within triggers can cause problemswhen called from other applications; in this case it will either be aweb site using ASP.or an application developed in FOXPRO. I can't findwhere I read this originally, so it's entirely possible I imagined itor misunderstood it, but I'd very much appreciate it if someone couldconfirm whether or not this is the case?Many, many thanks in advance!Much warmth,Murray
Ok I have a query "SELECT ColumnNames FROM tbl1" let's say the values returned are "age,sex,race".
Now I want to be able to create an "update" statement like "UPATE tbl2 SET Col2 = age + sex + race" dynamically and execute this UPDATE statement. So, if the next select statement returns "age, sex, race, gender" then the script should create "UPDATE tbl2 SET Col2 = age + sex + race + gender" and execute it.