|
Hello every one,
I need to improve my SQL skills as much as I can
I know how to do the basic stuff but when I try to do something a bit complex
I'm stuck
Any ideas?recommendations?
thanx a lot
Emily
|
|
|
|
|
Presumably you are using a dedicated IDE, SQL Server Management Studio SSMS, or one dedicated to your database.
I would recommend SQL Server Central. Microsoft SQL Server tutorials, training & forum.[^] as an excellent resource dedicated to SQL Server, concentrate on TSQL rather than the DBA stuff. Also try researching books on writing SQL.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In addition to the suggestion from @Mycroft-Holmes (which I agree with by the way), don't forget that there are lots of articles here on Code Project that can help you improve on specific topics within the "SQL World" ... SQL articles on CodeProject[^]
Use the star-rating system to get a view on how "good" the rest of the membership think the article is
|
|
|
|
|
|
hi all,
I have few SSIS Packages that have ConnectionStrings configured within Package Config file, now I want to set multiple variables values using Package configuration file, but the package configuration file is taking only one variable value, do I need to create different Package Configuration file for each variable that I want to set or is there any way I can set all the variable values using Package Configuration file.
And one more thing is I am going to deploy the SSIS Packages on the Server, where I need to put the Package Configuration Files at different locations, how can I change the Package Configuration Files Path? I am using SSDT 2012 and VS 2012, is it a problem?
Please I need this help, any help would be grateful, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 3-Apr-18 16:40pm.
|
|
|
|
|
Hi all,
I am trying to insert values into Table variable within Dynamic Sql, I am able to select values from Table variable but not able to insert values in to the Table variable.
Here is how I am selecting values from Table variable
CREATE TYPE IntegerTableType AS TABLE (ID INT);
go
DECLARE @TempVehicles IntegerTableType;
INSERT @TempVehicles
values (1);
DECLARE @SQL NVARCHAR(MAX);
SET @SQL ='SELECT *
FROM @TempVehicles;';
EXECUTE SP_EXECUTESQL @SQL,N'@TempVehicles IntegerTableType READONLY',
@TempVehicles;
IF EXISTS (SELECT 1 FROM sys.types WHERE is_table_type = 1 AND name ='IntegerTableType')
DROP TYPE [dbo].IntegerTableType;
GO
But when I am trying to insert values as below, I am not able to insert.
IF NOT EXISTS (SELECT 1 FROM sys.types WHERE is_table_type = 1 AND name ='Results')
CREATE TYPE Results AS TABLE (TableName nvarchar(500), ColumnName nvarchar(500))
GO
Declare @Tables table (Id int identity(1,1), TableName nvarchar(500))
declare @Columns table (Id int identity(1,1), ColumnName nvarchar(500))
declare @Results AS Results
declare @IdMin1 int, @IdMax1 int, @IdMin2 int, @IdMax2 int, @col varchar(500), @cmd varchar(max), @TableName nvarchar(500)
insert into @Tables(TableName)
SELECT t.name
FROM sys.tables AS t
INNER JOIN sys.schemas AS s
ON t.[schema_id] = s.[schema_id]
WHERE s.name = N'dbo'
order by t.name
select @IdMin1=min(Id), @IdMax1=max(Id) from @Tables
while(@IdMin1<=@IdMax1)
begin
set @TableName = (select top 1 TableName from @Tables where Id = @IdMin1)
<pre>
delete from @Columns
insert into @Columns(ColumnName)
SELECT c.name FROM sys.tables t JOIN sys.columns c ON t.Object_ID = c.Object_ID
WHERE t.Name = @TableName
order by c.name
--insert into @Results (TableName) values(@TableName)
select @IdMin2=min(Id), @IdMax2=max(Id) from @Columns
while(@IdMin2<=@IdMax2)
begin
set @col=''
select @col=ColumnName from @Columns where Id=@IdMin2
SELECT @cmd = 'IF EXISTS (SELECT top 1 * FROM ' + @TableName + ' WHERE [' + @col +
'] IS NULL) BEGIN insert into @Results (TableName, ColumnName) values( ''' + @TableName +''',''' + @col + ','') end';
begin try
--select @cmd
--EXEC(@cmd)
EXECUTE SP_EXECUTESQL @cmd, N'@Results Results READONLY', @Results;
end try
begin catch
SELECT @col=@col + ', Error Message: ' + ERROR_MESSAGE()
end catch
--insert into #Results (ColumnName) values(@col)
set @IdMin2+=1
end
set @IdMin1+=1
end
select * from @Results where TableName is not null order by TableName, ColumnName
IF EXISTS (SELECT 1 FROM sys.types WHERE is_table_type = 1 AND name ='Results')
DROP TYPE [dbo].Results;
GO
Can anybody please help me how can I finish this and let me know why is it not inserting into Table variable using Dynamic Sql, is there any way to perform that action. Any help would be much helpful, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Is there a reason why you are creating a user defined TYPE for each table? Why not create a table variable
Declare @Tbl TABLE(ID int)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Because I am trying to insert into the Table variable using dynamic sql, its not doing, can you please help me how can I insert into the Table variable within dynamic sql without using the User Defined Type? Thanks in advance buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
indian143 wrote: @Results Results READONLY
There's a slight clue in that line to suggest that you can't write to the table valued parameter.
Table-valued parameters must be passed as input READONLY parameters to Transact-SQL routines. You cannot perform DML operations such as UPDATE , DELETE , or INSERT on a table-valued parameter in the body of a routine.
If you need to write to the table, use a temp table instead. It looks like you at least started trying to do that - one of the commented-out lines refers to #results instead of @results .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi Rick, yes that's true I did achieve by using the Temp Table but I am always puzzled if I have any way to insert using table variable rather than temp table, because I don't like to drop, hence like to use Table variable which will be lost after the scope.
Any other way I can insert into table variable within dynamic sql?
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you pass a table valued parameter around, you can't modify the contents. You can only modify it in the procedure where it's declared.
A temp table is definitely the way to go, and there's no danger in dropping it. Each active connection gets its own set of temp tables, so there's no chance of the code executing on one connection affecting a temp table from another connection.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Everyone, so i have a problem with my MySQL database, whenever i try to import the database i get an error that says
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
I was running a site and using VestaCP i wanted to reinstall my server, so i simply exported the database from PHPmyAdmin and then reinstalled the whole server.
Then again i installed VestaCP and now when i am trying to import the Database i get the following error
ERROR 1064 (42000) at line 31734: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''C:24:"WPSEO_Sitemap_Cache_Data":152414:{a:2:{s:6:"status";s:2:"ok";s:3:"xml";s:' at line 2
It is a wordpress database, i really have no clue as to whats happening. If you guys can help me out i'd appreciate it.
I read some articles on Google, and i think its related to the Mysql or PHp versions. But i couldn't find answers or threads specifically for this issue. So please help me out ASAP because my website is down from days. Thanks
|
|
|
|
|
Can you not post the full SQL? But I suggest you look at the second of the first pair of apostrophe's, which on the face of it should either not be there or be escaped.
|
|
|
|
|
You are taking about these
''C:24 apostrophes? i just have to remove this from the sql file and upload it?
I cant post the full sql file because its 1 GB and very very large.
|
|
|
|
|
Quote: just have to remove this from the sql file Not necessarily, it depends on what comes before it - if those are just two apostrophe's on their own in the middle of a longer statement they're fine, and the problem lies elsewhere. BUT you shouldn't really be posting strings in an SQL statement anyway - it's a security risk; look into paramatised queries instead And they are far less prone to syntax errors
|
|
|
|
|
Member 13755227 wrote: I cant post the full sql file because its 1 GB and very very large.
1 GB?
I thought the limit is about 1 Mb...
|
|
|
|
|
What limit are you talking about? A 1 meg database would be pretty small these days.
|
|
|
|
|
jschell wrote: What limit are you talking about? A 1 meg database would be pretty small these days.
The SQL file. I meant a limit for SQL query, not a limit of the database itself.
If I incorrectly understood the OP then sorry!
|
|
|
|
|
Member 13755227 wrote: at line 2
So right at the top of the file.
The error message certainly seems to suggests that the imported file is NOT sql.
If you export a database using process X then you must import it using process X also. Because the export and import can use a format specific to that process and not a general one.
|
|
|
|
|
Hello All,
I have a SSIS package wherein the first step is excution of C# program to convert a csv file to excel file. The second step is the loading of this excel file into a table.
This programs with no errors when execute from IDE.
Now, i am setting the process as SQL server agent Job, and i give the path to the package for execution. The job fails with message that "Access is denied".
I moved the package to C:\ drive. Now the program fails on first step with null reference.
why the difference in results when executed from SSIS package environment versus the SQL server agent job?
I did resolve this issue by removing the C# program execution and set it up as scheduled task, but would like to understand the behaviour.
Many thanks
|
|
|
|
|
Sorry I can't help with the problem, but I am intriqued as to why you would convert a CSV to "excel" just to load it to a table... the step is totally unnecessary unless you need the xlsx file for something else as well.
|
|
|
|
|
There is one field in the csv file, a freeform field. The users have ability to type anything in this field, along with special characters. Since there was no common delimiter, had to go with converting the csv file to excel file route to load this file using SSIS.
|
|
|
|
|
So it would be surrounded by quotes in the csv.. I stand by my comment
|
|
|
|
|
You should specify UNC paths when you're loading files in your packages. That way, it will work no matter where you put the file (as long as you're using the correct UNC path of course).
BTW, you can write a script task in a package that will import that data (as opposed to running an external application).
I wrote an article not to long ago that includes code to import excel and CSV files - SQLXAgent - Jobs for SQL Express - Part 3 of 6[^]
I think you might find it useful. I'm currently extracting that code into it's own assembly for easier inclusion into projects like yours. It even goes to some length to determine the data type represented in each column.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Hi,
I have taken a backup of Database A from Server A1 then I restored this Database with name B on Server B1, now the application is working fine with Database A on Server A1 but not working with Database B on Server B1, I have checked the users, I have the users and I have given access to the users when it didn't work I have dropped the User which is connecting from Web application and recreated that user and granted the same permissions it had previously on this Database but still I am not able to use the application.
Here is the error that I am getting:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Any help would be greatly helpful thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|