« first day (2393 days earlier)      last day (1925 days later) » 

05:11
0
Q: Replication of the current Identity

Elby JoyI have a table named 'Temp_Identity'.Its one column is a IDENTITY Column. When we doing the replication,data from this table is correctly replicated.But its current identity is not replicated. ie, the current identity of that table in production DB is 10. But in the replication data base,it is ...

 
7 hours later…
12:19
Hello, Good day !
is anybody here
SQL 2008 R2, need some assistance on a join
select * from INVENTORY
inner join location on Location.Location_Id = Inventory.Location_ID
inner join Container_type on Container_type.Inventory_ID = Inventory.Inventory_ID
inner join Product on Product.Product_ID = Inventory.Product_ID
inner join CPN_PHY_CHAR on CPN_Phy_char.CPNKIT = Product.MSDS_ID
where location.Station in  ('LGA', 'LGA (Envoy)', 'JFK', 'JFK (Envoy)') and (CONTAINER_TYPE.Container_Size > 0)
The CPN_PHY_CHAR table misses some CPNKIT. I want to find all inventory records that has no CPN. MSDS_ID and CPNKIt are same data bu just different column names as per standards.
 
2 hours later…
14:15
@Sakthivel If I am understanding what you need, then you cannot inner join. If you want rows where they are in MSDS_ID and not in CPNKIT you need right join
that would just return nulls for CPN's columns
 
7 hours later…
21:21
I need some help on building an sql query, I have below two queries, I want to combine the sum of debit substracted from debit and then insert it into another table

select sum(amount) from ACCOUNT_TRANSACTIONS where CUSTOMER_USER_NAME='55555' and transaction_type='credit' and account_type='customer' and IS_DELETED='false'

select sum(amount) from ACCOUNT_TRANSACTIONS where CUSTOMER_USER_NAME='55555' and transaction_type='debit' and account_type='customer' and IS_DELETED='false'
@Ayub Use conditional aggregation
So you want the sum of debits - sum of credits?
yeah thats correct and then insert into another table
select sum(case when transaction_type='credit' then amount else 0 end)-
       sum(case when transaction_type='debit' then amount else 0 end)
from ACCOUNT_TRANSACTIONS
where CUSTOMER_USER_NAME='55555'
      and account_type='customer'
      and IS_DELETED='false'
it is sum of credits - sum of debits and insert in to another table
ok let me check that
CASE
WHEN ServiceFromDate = ServiceToDate THEN BilledAmount
ELSE BilledAmount/DATEDIFF(DAY, ServiceFromDate, ServiceToDate)
END AS MyDailyRate
When I test this calculation it's off my a couple of digits.
by*
21:37
Sample data and expected results please
thanx @Sami the query looks good !!
@Ayub Welcome ;)
22:04
what is wrong with this query if I want to insert the results from select?

insert into My_table(id,USER_ID,balance,MODIFIED_BY,MODIFIED_DATE) select APP_USER_JAYPAY.nextval,user_id,balance,modified_by,modified_date
from (u.user_id,sum(case when ac.transaction_type='credit' then ac.amount when transaction_type = 'debit' then - ac.amount end) as balance,
'60' as modified_by,
sysdate as modified_date
from ACCOUNT_TRANSACTIONS ac,APP_USER u
where ac.account_type='customer'
and ac.IS_DELETED='false'
when I execute I get missing parenthesis error
Please post your code as formatted text, it's hard to read as it is now
ok
insert into My_table(id,USER_ID,balance,MODIFIED_BY,MODIFIED_DATE) select APP_USER_JAYPAY.nextval,user_id,balance,modified_by,modified_date
from (u.user_id,sum(case when ac.transaction_type='credit' then ac.amount when transaction_type = 'debit' then - ac.amount end) as balance,
'60' as modified_by, sysdate as modified_date from ACCOUNT_TRANSACTIONS ac,APP_USER u where ac.account_type='customer' and ac.IS_DELETED='false'
and u.MOBILE=ac.CUSTOMER_USER_NAME group by ac.CUSTOMER_USER_NAME,u.USER_ID)
INSERT INTO YourTable (Column1, Column2 ...)
SELECT Column1,
            Column2,
            ...
FROM
( SELECT ...) AS AliasHere
ok, what if there is a sequence and also sum(case ) in the select fields ?
thank you, I was missing inner select
Why are you still the Old-Style join?
insert into My_table(id,USER_ID,balance,MODIFIED_BY,MODIFIED_DATE)
select APP_USER_JAYPAY.nextval,
       user_id,
       balance,
       modified_by,
       modified_date
from (
       SELECT u.user_id,
              sum(case when ac.transaction_type='credit' then ac.amount when transaction_type = 'debit' then - ac.amount end) as balance,
              '60' as modified_by,
              sysdate as modified_date
      from ACCOUNT_TRANSACTIONS ac,APP_USER u
      where ac.account_type='customer'
Why not
from ACCOUNT_TRANSACTIONS ac INNER JOIN APP_USER u
ON ac.UserID = u.ID
22:19
could you let me know which approach is better ? I am not that strong in sql

« first day (2393 days earlier)      last day (1925 days later) »