|
this SQL code takes current date and time of ur PC
select substring(cast(getdate()as varchar),1,11) as datte, <br />
substring(cast(getdate()as varchar),14,8) as ttime
|
|
|
|
|
Thnaks it is useful for me
Regards,
Jayamaruthi.A
|
|
|
|
|
|
select cast(cast(getdate() as int) as datetime) as DateVal,
getdate()-cast(getdate() as int) as TimeVal
|
|
|
|
|
I am trying to issue a command to MS SQL to perform a backup to a disk file, from a VB.NET 2005 program.
The command structure is as follows :-
BACKUP DATABASE Weighbridge TO DISK = 'C:\SQLBackup\MyServerName\MyDatabaseName_20060803_1108.BAK'
My program reports the following error :-
Incorrect syntax near '\'.
My code is as follows :-
<br />
Private Sub IssueBackupCommand(ByVal Server As String, ByVal Database As String, ByVal BackupPath As String)<br />
<br />
Dim sConnectionString As String<br />
Dim sCommand As String<br />
Dim sSql As String<br />
<br />
Dim connection As New System.Data.SqlClient.SqlConnection<br />
Dim command As New System.Data.SqlClient.SqlCommand<br />
<br />
Try<br />
sConnectionString = "Data Source=" & Server & ";Initial Catalog=" & Database & ";Integrated Security=True"<br />
<br />
sCommand = BackupPath & "\" & Database & "_" & Format(Now(), "yyyyMMdd") & "_" & Format(Now(), "HHMM") & ".BAK"<br />
sSql = "BACKUP DATABASE " & Database & " TO DISK = '" & sCommand & "'"<br />
<br />
With connection<br />
.ConnectionString = sConnectionString<br />
.Open()<br />
With command<br />
.Connection = connection<br />
.CommandType = CommandType.Text<br />
.CommandText = sCommand<br />
.ExecuteNonQuery() '<--- Error produced here<br />
End With<br />
.Close()<br />
End With<br />
<br />
Catch ex As System.Exception<br />
MessageBox.Show(ex.Message)<br />
Finally<br />
command.Dispose()<br />
command = Nothing<br />
If connection.State <> ConnectionState.Closed Then connection.Close()<br />
connection.Dispose()<br />
connection = Nothing<br />
End Try<br />
<br />
End Sub
Any help appriciated
Thanks
Steve Jowett
-- modified at 6:53 Thursday 3rd August, 2006
|
|
|
|
|
Is the error issued by the database??
thanks,
SeEa
|
|
|
|
|
The error seems to be issued by SQL Server. When I run a query consisting of :-
BACKUP DATABASE master TO DISK 'C:\master.BAK'
I get the following message returned :-
Msg 102, Level 15, State 1, Line 1<br />
Incorrect syntax near 'C:\master.BAK'.
Steve Jowett
|
|
|
|
|
backslash is an escape character.
Try C:\\master.bak
WM.
What about weapons of mass-construction?
|
|
|
|
|
Tried your suggestion, but still get the same result
Msg 102, Level 15, State 1, Line 1<br />
Incorrect syntax near 'c:\\master.bak'.
Steve Jowett
|
|
|
|
|
I have found the problem. There is a small error in the VB.NET code
.CommandText = sCommand
Should be
.CommandText = sSql
Da Darrrrrrrr
Thanks everyone for your help anyway
Steve Jowett
|
|
|
|
|
Hahaha, ok clearly missed that one
Glad it works now.
WM.
What about weapons of mass-construction?
|
|
|
|
|
Hi ,
I want to read the distinct records with multiple columns.
for example,
tableA
--------
OID CODE
1 READ
2 READ
3 WRITE
4 WRITE
select distinct CODE, OID from tableA
it gives,
READ 1
READ 2
WRITE 3
WRITE 4
but expected result was,
READ 1
WRITE 3
|
|
|
|
|
man this sql script is not work like this ....
u should use the group by function to get that effect and any aggr functions
select CODE, min(OID) from tableA
group by CODE
This should fetch you the result
thanks,
SeEa
|
|
|
|
|
hmm not sure exactly what your looking for so I'm going to assume you want:
the lowest OID for each distinct CODE
which is:
select CODE, MIN(OID) from tableA group by CODE
which would give your desired result.
DISTINCT is no way appropriate for what your trying to do in this case!
|
|
|
|
|
don't assume you have OID in number format
OID CODE
x READ
y READ
z WRITE
..
this scenorio
expected result will be,
OID CODE
x READ
z WRITE
|
|
|
|
|
if you didn't want us to assume , then you should have stated clearly in your orig post, instead of wasting our time.................
dunderhead
|
|
|
|
|
In that case also teh above approach of grouping by should work !!!
thanks,
SeEa
|
|
|
|
|
Hi,
I need an suggestion how to run sql server in local. In my system sql server was not running in local, but when I connect to our remote data base with it's IP ,username and password, I can able to connect, but not in the local system sql server.I am using windows XP OS. I tried to register a new connectio to my local but i am getting an error the Acdess denied or connection faild.
Plz any one suggest me how to troubleshoot this problem
Regards
Exelio
|
|
|
|
|
Try the sql authentication method and make sure that the username and the password supplied are correct..
thanks,
SeEa
|
|
|
|
|
Hi, good day.
I have a question about the checkbox in datagrid.
The problem is i have a datagrid in my page and i have 4 checkbox per row in the datagrid. I use the radio button to select the record and i can check the checkbox for certain specify action.
For an example, i select the record to be print in different type of report format. The checkbos is use to select which report format need to be printed out.
Did anyone can help me to solve this problem? Thanks..
-- modified at 22:53 Wednesday 2nd August, 2006
Best Regards,
Pei Sun
|
|
|
|
|
Can anyone tell me what's wrong with this statement (purpose is to update a row if it exists and create it if it doesn't (but that should be obvious)).
IF EXISTS(SELECT * FROM Assemblers WHERE ID = @id)
BEGIN
UPDATE Assemblers SET Name = @name WHERE ID = @id
END
ELSE
BEGIN
INSERT INTO (ID, Name) VALUES (@id, @name)
END
Error is: Incorrect syntax near '('.
Note: I tried writing this on my own, couldn't get it accepted and did a search and someone had posted this code (except for the differing table structures and names) on one of the MSDN forums.
-- modified at 8:39 Wednesday 2nd August, 2006
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
IF EXISTS(SELECT * FROM Assemblers WHERE ID = @id)<br />
<br />
UPDATE Assemblers SET Name = @name WHERE ID = @id<br />
<br />
ELSE<br />
BEGIN<br />
INSERT INTO ????? (ID, Name) VALUES (@id, @name)<br />
END
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thank you very much for pointing out the obvious, that was a case of staring at the code for much too long
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Ed.Poore wrote: that was a case of staring at the code for much too long
We all do that!
Kevin
|
|
|
|
|
what is the major and minor differences between SQL2000 and SQL2005
divya
|
|
|
|