Quantcast
Channel: Forum Getting started with SQL Server
Viewing all 8979 articles
Browse latest View live

Help with Division Calcualtion

$
0
0

Hi, 

I need help with the following logic to be put into some code if possible please? I am looking at working out the renewal rate of contracts but I'm not too sure how to code this up. 

I need to essentially write out: 

Value of contracts renewed (Variable: Contract_Type = '00 Renewal'and Variable: Date_Start = This monthand Variable: 'Contract_Amount')

/

Value of contracts due for renewal (Variable: Date_End = This monthand Variable: 'Contract_Amount')

The Output I am looking for would be:

Date      %

Jan 18   22%

Feb 18   13%

Mar 18   70%

etc..........      

I hope this makes sense, if it doesn't please let me know. 

Thanks in advance


Error 0xc002f210 during Import of Data

$
0
0
I am using the same process/steps to import data every time.  Sometimes I can import the data, sometimes it does not work.  There is no pattern or reason, just random working or not working.  I am using SQL Management Studio 2017.  Anyhow, when it does not work, I receive Error 0xc002f210 when I try to import data.  The error message reads:  "failed with the following error:  'There is already an object named....in the database." however, there is not another object with the same name.  Can anyone help me with fixing this error so that I can import data consistently without having this error appear?

Condense Record output

$
0
0

Hi,

My code below outputs 3 records as the Date variable is YYYY-MM-DD of which I have formatted to MMM-YY. How do I condense these please so I only show 1 record with the total value? 

select 
usummary.[ft_type],
format (LD.date_in, 'MMM-yyyy') as Date,
sum(LD.total_val_new)

from LD
left join usummary
on usummary.j_number = LD.j_number

where LD.date_in like '2019-01%'
and usummary.[ft_type] = '26Q'


group by 
usummary.[ft_type],
LD.date_in

My output is

FT_TYPE   DATE_IN     No_column Nam

26Q          JAN-18        1000

26Q          JAN-18        2000

26Q          JAN-18        4000

I want my output to be 

FT_TYPE   DATE_IN     No_column Nam

26Q          JAN-18        7000

Thanks

Using Import and Export Data Wizard - Large text truncates

$
0
0

I am new to using SQL Server and have ben trying to import some data from a flat file in text format, which has a very large amount of text in one of the fields.  When I try to import using the wizard it reports some data is truncated.

Here are the errors:

Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "Verse" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
 (SQL Server Import and Export Wizard)
 
Error 0xc020902a: Data Flow Task 1: The "Source - Verses2_txt.Outputs[Flat File Source Output].Columns[Verse]" failed because truncation occurred, and the truncation row disposition on "Source - Verses2_txt.Outputs[Flat File Source Output].Columns[Verse]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
 (SQL Server Import and Export Wizard)
 
Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "D:\Downloads\Verses2.txt" on data row 2.
 (SQL Server Import and Export Wizard)
 
Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on Source - Verses2_txt returned error code 0xC0202092.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)

The fields in the table are: 

VID (Int)

Event_Type    (Int)

Sub_Type       (Int)

Verse              nVarchar(Max)

Am I right in specifying thatall the source data are strings, as it comes from a text file?

Any ideas on how I can get this to import without an error?

Limitations of View

$
0
0

Hi Experts,

I am new to SQL. I learn a little for View.

Can someone give me a explanation. I will appreciate a lot if you provide me some examples.

What data type should I put decimal value?

$
0
0

Hi guys,

Does anyone know what data type should I put for data up to 9 decimal places? float or ?

Example value : 103.6349816 and 1.2703401666

Regards,

Tan

Add one subquery to existing query to get the percentage from another table

$
0
0
i am working on multi level marketing website binary tree based.Below query is returning me total number of left side and right side members. Below query is working fine. Now i want to add one more condition in the below query. That basically will be the sub query. i am not familiar with the sub queries or nested queries. so i want help from you guys.


cmd = new SqlCommand("declare @nodeid int = '"+cust_id+ "';with cte as

(select cust_id, parentid, joinside, null left_node, null right_node from  user_detail

where cust_id = @nodeid union all select t.cust_id, t.parentid, t.joinside,ISNULL(cte.left_node,

CASE WHEN t.joinside = 0 THEN 1 ELSE 0 END) left_node,ISNULL(cte.right_node,

CASE WHEN t.joinside = 1 THEN 1 ELSE 0 END) right_node from  user_detail t inner join

cte on cte.cust_id = t.parentid ) select @nodeid nodeid,

SUM(left_node) LeftNodes,SUM(right_node) RightNmodes from cte option (maxrecursion 0)", con);


What i want is: i have another table installments in which there is a flag column which contains values "paid" and "not paid". i want to count %age of left side and right side customers who have paid the installments of specific id. i want this condition in the above query. i hope you guys understand my question. Thanks

SQL Query Modification Request

$
0
0

Hello Experts,

Can someone help modify a SQL script.

The following script will compare columns A B C from TableA and TableB and if it sees a match will output the rows as shown in the following image.

select convert(VARCHAR,0) Is_Deleted, A.A, A.B, A.C, A.D, A.E, A.F
from TableA A
inner join TableB B on B.A = A.A and B.B = A.B and B.C = A.C
union all
select convert(VARCHAR,1) Is_Deleted, B.A, B.B, B.C, B.D, B.E, B.F
from TableB B
inner join TableA A on A.A = B.A and A.B = B.B and A.C = B.C
order by A, B, C

However, I would like the code modified.

I still need sql to find a match on columns A B C but only produce an same output if Column B have the same record, of say bb. At moment, the query matching if all Columns are the same. So because there is a match of xx PP dd the query is providing an output, but I only need the output if the columns were xx bb and dd.

So I only want the above query to produce a result of the TableA and TableB, look like the following:

TableA

TableB

As you can see there is not only a match on ABC, but also on B

Please let me know if you need further information


carlton


Permutations and combinations of multiple return codes

$
0
0
hi guys, can anyone help me with this, i have 6 columns with the "return codes" for SEO in each column i want to do all possible permutations and combinations of each return code in one with other return codes in other column's and want to pass it in a Store procedure in the recursive function Any help would be greatful....... Eg:-Return code1 -'IEK2EK53' rETURN CODE2-'2EKR531' Return code3-'3M4RT15U' etc... so it has to be 1EK2EK53',2EKR531',3M4RT15U' 'IEK2EK53',2EKR531' 'IEK2EK53','3M4RT15U' 2EKR531','3M4RT15U'. 

Do I need to write scripts to connect SQL to Tableau?

$
0
0

Hi all,

Just want to ask anyone who is using SQL server for Tableau purpose.

Do I need to write a script to connect my data to sql.

Right now I created a table with all the variables that I have in my data type and trying to import the flat file source 

is it correct?

Can anyone advice me . Thank you so much:)

Regards,

Tan

Patching

$
0
0
Hi All, 

I am trying to gather some SQL server version and OS lvl information and thinking what is the best way to do it since I have more than 10 servers.
1. How can I get the OS and SQL server current patch level information? is it select @@version? or do we have better options?
2. What should be the right patch level, How do you know if this patch is outdated. Is it I have to go Microsoft site or just google?

Trying to learn the best approach for simple work task. Please share your advise. 

Have a wonderful day! 

Length of varchar column - is there an advantage to using 255?

$
0
0
I often come across columns that are varchar(255), so presumably this is a convention of sorts. 255 is 2^8 - 1. So is there something 'magical' about lengths that are 2^n - 1? Or just specifically 255? Is there a performance or storage optimisation advantage to certain specific lengths? Or is this just old wisdom which is no longer applicable to current versions of MariaDB and MySQL?

SQL Server in Hyper-V

$
0
0

Hello,

I'm thinking of moving my SQL databases in VMs to help with the constant problem of disk space.

Could you please point me to some useful documents?

Any tips on improving hard disk performance for Sql Server?

Thank you.

Pull out accounts that don't match 2 tables

$
0
0

Hi,

I need to create a report that reports on accounts that are in table 1(KT) but not in table 2(KP). 

select 
KT.j_number, 
KT.c_name, 
KT.total_contract, 
KP.invoiced_total,

from 
KT 
left join KP
on KT.j_number = KP.job

Any idea how I would write this logic out please?

Error converting data type varchar to numeric.

$
0
0

Hi,

Here is my function

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[uf_getCamraTime](@camra_time decimal )
RETURNS decimal
AS
BEGIN

declare @num as decimal(10,2)
set @num=@camra_time
select @num=convert(varchar(10),floor(floor(@num/60)/60))+':'+convert(varchar(10),floor(@num/60)-(floor(floor(@num/60)/60))*60)+':'+convert(varchar(10),floor(@num-floor(@num/60)*60))

-- Return the result of the function
RETURN @num

END
GO

When I run it like [uf_getCamraTime] 53784.41 getting Error converting data type varchar to numeric.


Itsme


QUERY PERFORMANCE BAD WHEN RUN ALL TOGETHER

$
0
0

Dear DBAs and developers

i have this query when running all together it takes forever, 

but when run subquery part and main query seperately they both return results very fast

SELECT COUNT (*)
FROM PS_RD_SITE S, PS_RD_DUMMY C
WHERE S.BO_ID_PARENT=C.BO_ID
AND S.TRANSFERSTATUS<>'T'
AND S.TWC_ENROLSTATUS_CD IN('PE','EN')
AND NOT EXISTS (SELECT * FROM PS_RF_AGREEMENT A WHERE A.SETID='SHARE' AND A.AGREEMENT_CODE=S.SITE_ID AND A.AGR_RENEWAL_NUM=1 AND AGRT_STATUS='005')
AND C.DUMMYID IN (
--– bELOW IS THE SUBQUERY PART
SELECT VB_NUMBER
FROM TWC_ANGLE_VB_FUNDER_INFO FUNDER_INFO
WHERE VB_NUMBER = 'B38566' OR FUNDER_ID = 'B38566' 
)

PLEASE ADVISE


k

Azure elastic query from tutorial resulting in error msg 46823, error retrieving data from database.staging.

$
0
0

Hello, 

I have attempted to use the elastic query tutorial (code below) and I am getting a 46823 message which says "Error retrieving data from database.staging" - which doesn't help me at all. Please let me know why I would get this error using the following.

CREATE MASTER KEY ENCRYPTION BY PASSWORD ='redacted';CREATEDATABASE SCOPED CREDENTIAL ElasticDBQueryCredWITHIDENTITY='redacted',
SECRET ='redacted';CREATE EXTERNAL DATA SOURCE MyElasticDBQueryDataSrc WITH(TYPE = RDBMS,
    LOCATION ='redactedazure.database.windows.net',
    DATABASE_NAME ='Redacted_Staging',
    CREDENTIAL = ElasticDBQueryCred,);CREATE EXTERNAL TABLE[dbo].[CustomerInformation]([CustomerID][int]NOTNULL,[CustomerName][varchar](50)NOTNULL,[Company][varchar](50)NOTNULL)WITH( DATA_SOURCE = MyElasticDBQueryDataSrc)SELECT OrderInformation.CustomerID, OrderInformation.OrderId, CustomerInformation.CustomerName, CustomerInformation.CompanyFROM OrderInformationINNERJOIN CustomerInformationON CustomerInformation.CustomerID = OrderInformation.CustomerID;

Msg 46823, Level 16, State 1, Line 1 Error retrieving data from redactedazure.database.windows.net.Redacted_Staging. The underlying error message received was: 'Error retrieving data from redactedazure.database.windows.net.Redacted_Staging. The underlying error message received was: 'Error retrieving data from... (repeats)

Any idea why?

SQL 2017 Certifications?

$
0
0
Any news on when Microsoft will release certification exams for SQL 2017?  I have searched everywhere, but no luck.  My boss wants to know when I can get certified on SQL 2017.

replicating COUNTIF excel function in SQL

$
0
0

Hi,

I have some code that pulls data from SQL Server, but I want to add an extra column onto the results that counts the distinct items in one specific column and adds that to the end of each row.

For Example

Column1  Column2  Column3  Column4

Dave        24           house      married

Dave        24           car          married

Bob          32           House      single

George     12           house       divorced

I want an extra column on the end that will do what countif does in excel so that it tells me how many times each item in column1 appears in that column.

Is that possible?

The backend version is not supported to design database diagrams or tables

$
0
0

Hi Experts,

Why I always get the error message when creating table in SSMS.

The backend version is not supported to design database diagrams or tables.

Thanks in advance.

Viewing all 8979 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>