|
|
Can we skip format file (-f switch) at all?
I got it working by indicating column tye SQLVAR instead of SQLINT and let SQL do conversion herself - however it's still ridiculous having (mandatory) to specify format file...?
Thanks
dev
|
|
|
|
|
Is it possible to skip -f switch (i.e. not supply format file) and let bcp to do this job herself (i.e. infer field type auto like old days?)
C:\somedir\bcp.exe DEV.dbo.SomeMixedData in C:\somedir\output\output_abc_mixed.txt -n -S SomeSErver -T
Starting copy...
0 rows copied. << Just can't get it working without format file.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1
When open with Notepad my sample file resembles:
20100701,1.110000e+000,2.220000e+000
20100702,3.330000e+000,4.440000e+000
20100703,5.550000e+000,6.660000e+000
And my simple table:
CREATE TABLE [dbo].[SomeData](
[Col1] [varchar](255) NULL,
[Col2] [varchar](255) NULL,
[Col3] [varchar](255) NULL
)
dev
modified on Tuesday, July 13, 2010 7:02 AM
|
|
|
|
|
Hi All,
How to get sum of a column upto the current row for each row into a different column in SQL Server.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
Hi,
There's multiple ways of calculating a running total. This article[^] shows three of those solutions.
I are Troll
|
|
|
|
|
|
Not a full solution, but a step towards it:
Let us assume a table "Table1" with following columns and values:
ID val total
1 12 <NULL>
2 23 <NULL>
3 2 <NULL>
4 14 <NULL>
Now you can update the "total" column for each row with a query like the one below for ID=3:
UPDATE table1
SET total = tmp.result
FROM (SELECT MAX(ID) AS maxid, SUM(val) AS result
FROM Table1
WHERE (ID <= 3)) TMP
WHERE table1.id = tmp.maxid
Next, replace "3" by a parameter and run the query for every ID value...
|
|
|
|
|
bhiller wrote: run the query for every ID value...
What with a cursor or a while loop, what happens if he has 100k IDs. This is a bad solution, using the running total tools will give a much better result.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm currently maintaining a Visual Basic project that makes use of tnsping. In order to do a tnsping, it uses a ProcessStartInfo instance to make the call as if it were using the command prompt(DOS). I was wondering if a library exists (Oracle.DataAccess maybe?) or if there's something built into the .NET libraries that will allow me to do the tnsping without the ProcessStartInfo. Could anyone point me in the right direction?
Thanks in advance for all of your answers.
|
|
|
|
|
SELECT DISTINCT ISNULL(CONVERT(VARCHAR,DR_TimeIn,103),'NOT CHECKED')AS DATE,
DR_EmployeeID AS EMPID ,
EM_FirstName +' '+ isnull(EM_MiddleName,' ' )+' '+isnull(EM_LastName,' ') AS EMPNAME,
FROM SG_Daily_Register
to accept the null values of lastname and firstname...I used the 'isnull' which is not correct..Pls correct the procedure
|
|
|
|
|
|
Try COALESCE instead of ISNULL
modified 19-Nov-18 21:01pm.
|
|
|
|
|
SELECT DISTINCT DECODE(DR_TimeIn, NULL,'NOT CHECKED',DR_TimeIn) as Date,
.............;
If you are using Oracle DECODE if the best.
OR for other Database Server:
SELECT IIf(TimeIn is null,'NOT CHECKED',TimeIn) AS [Date],
........;
|
|
|
|
|
It looks like you just forgot to wrap EM_FirstName in an isnull. Otherwise I don't see why that wouldn't work with MSSQL.
|
|
|
|
|
CONVERT(VARCHAR(5), (DATEDIFF(SS,MIN(FIRSTTIMEIN),MAX(LASTTIMEOUT)) / 3600)-(SUM(DATEDIFF(SS, FIRSTTIMEIN, LASTTIMEOUT)) / 3600))
+ '':'' +
CONVERT(VARCHAR(5), (SUM(DATEDIFF(SS,FIRSTTIMEIN, LASTTIMEOUT)) % 3600 / 60)-(DATEDIFF(SS, MIN(FIRSTTIMEIN), MAX(LASTTIMEOUT)) % 3600 / 60))
+ '':'' +
CONVERT(VARCHAR(5), (DATEDIFF(SS, MIN(FIRSTTIMEIN), MAX(LASTTIMEOUT)) % 60)-(SUM(DATEDIFF(SS, FIRSTTIMEIN, LASTTIMEOUT)) % 60))
When I used this.I got output as 0: -13: -16(negative values)
But I will have to get output as 0:13:16
how to remove negative sign from datetime in sql?
|
|
|
|
|
I may have done you a disservice, seems you have changed to datetime, well done.
Not sure if it will work with datetime but you might try ABS()
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
you've still not read the forum guidlines, you've still not learnt to use descriptive subject lines, you've still not learned to keep it in 1 thread.
You'll learn nothing from this response so i'll just paste the correction. Im not going to bother testing it, so check the syntax and try to understand it.
CONVERT(VARCHAR(5), ABS((DATEDIFF(SS,MIN(FIRSTTIMEIN),MAX(LASTTIMEOUT)) / 3600)-(SUM(DATEDIFF(SS, FIRSTTIMEIN, LASTTIMEOUT)) / 3600)))
+ '':'' +
CONVERT(VARCHAR(5), ABS((SUM(DATEDIFF(SS,FIRSTTIMEIN, LASTTIMEOUT)) % 3600 / 60)-(DATEDIFF(SS, MIN(FIRSTTIMEIN), MAX(LASTTIMEOUT)) % 3600 / 60)))
+ '':'' +
CONVERT(VARCHAR(5), ABS((DATEDIFF(SS, MIN(FIRSTTIMEIN), MAX(LASTTIMEOUT)) % 60)-(SUM(DATEDIFF(SS, FIRSTTIMEIN, LASTTIMEOUT)) % 60)))
|
|
|
|
|
Maybe if you swap both datetime arguments in DATEDIFF, your problem is gone?
|
|
|
|
|
It looks like you're trying to get the hour:minute:second difference between two datetime values. The simplest way to do that is subtract them, then convert that value to char and apply the appropriate formatting.
declare @t1 datetime, @t2 datetime
select @t1 = GETDATE()
--Select @t2 = @t1 + 1:02:03 (hh:mm:ss)
select @t2 = DATEADD(hour, 1, dateadd(minute, 2, dateadd(second, 3, @t1)))
select convert(varchar, @t2-@t1, 108)
You can find other formatting options here[^]
|
|
|
|
|
0:-13:-16
Please help me to remove the negative sign.I have to get output as
0:13:16
|
|
|
|
|
Are you asking for something as simple as string functions such as SQL Server's Replace()?
Depending on which database you're using, I'd google "your_database string functions"...
|
|
|
|
|
So are you still storing your date data as strings? Or have you done the sensible thing and changed it to a datetime format.
Sorry I already know the answer otherwise you would not be asking this question.
CHANGE YOUR DATE DATA TO DATATIME FORMAT!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
I have a report in which, I have to show the trend values like
sum for the same columns I have to show yesterday, 1week ago and 2weeks ago and 1month ago.
Like for example I have 2 columns and one date column. Now I have to write a query in such a way that
the sum(col1), sum(col2) for 1 day ago, 1 week ago and 1month ago in the same row.
Can anybody please help me in writing this query. Any link or any code snippet will be very much helpfull.
Thanks in advance.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
Break it into 4 queries, 1 for each time period doing the appropriate aggregation for each query, include the common key. Then join the 4 queries into 1 using the common key. I would use table vars to hold the temp data.
BTW I would not put my company name in your sig, it can be incorrectly construed (look it up).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi
how do i make sql statement to page the rows six per result
|
|
|
|
|