Author |
Topic |
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-04-26 : 13:14:05
|
Hello All,Please anyone help me..I want to retrieve column names which has values as "True".First Two Column Names are username and password which is varchar,the rest of them are bit.So I want only the column names,which has values 'True'.Is it possible?Here is the query that retrieves column names,that i have used.SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'SectionsAuthentication'Thanks in Advance.. |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-04-26 : 13:28:05
|
Yes, it is possible.Since you already know the column names, writing a query should be pretty simple. If you are asking for a dynamic query that is a little more compicated, but INFORMATION_SCHEMA.COLUMNS should have all the information you need to build such a query.http://www.sqlservercentral.com/articles/Best+Practices/61537/http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
|
|
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-04-26 : 13:35:39
|
Thankyou for your prompt reply..this is the result of my query..that i used to retreive the column names.in these only some of them have true values..so can you please help me,to modify my query..?Thanks In Advance..COLUMNNAMEusernamepasswrdCompanyDepartsAndDesgintsCompDetailsSecsAuthenticationBudgetingBudgetMangmntSavingsBudgetBudgetDeptWiseCRMManagemntcrmAppointmentsComplaintsInventoryInvMnangementProdMangerOrderByproductionStoreKeeperInvPlanningInvCostInvControlFinishedGoodsCustomersMaintCustomersSalesOrderSuppliersMaintSuppliersPurchaseOrderPurBillsPointOfSaleSalesInvoiceStockOnHandSalesRefundEmployeeMainEmployeeMaintPayrollDepartmentsViewPayrollAttSheetLeaveFormLoanBonusOTRecordgetpayrolladvanceempadvanceaccountsaccheadsaccpayableaccreceivableaccsalaryslipcostingclassifcostingacctofunctionelementsofcostinggenlegderreportsreportsmangmntcompfinancerptssalesrptssalessummrptsalesbillsrptsdispatchedgoodsrptsPurchaserptspurbillsrptspursummaryrptsemployeerptssalarysliprptsdeptsrptsaccspayrptsaccsreceivablerptsgenledgerrptsbankbankdetails |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-04-26 : 13:49:04
|
What do you want for output of the query?That is why I posed those link in my response above. If you supply sample data in a consumable format along with expected output, then we can create tested query against your data. The outcom is you get tested code and we don't have to go around and around asking questions (or at least as much). |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-29 : 00:39:20
|
do you mean retrieve list of columns in table with at least one true value in them?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-04-29 : 01:27:06
|
Thankyou for your reply, there both true and false values in it,I want the column names whose values are "TRUE" only. Is it possible? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-29 : 01:31:07
|
but there are multiple rows isnt it?So my question was what if there are both true and false value rows?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-04-29 : 01:43:30
|
.Firstly,Thankyou for reply.The result that i want is, the column names that is validated against username and password and whose values are true.I have tries two queries.,Select * From SectionsAuthentication Where UserName=@UserName And Passwrd=@Passwrd And @Valid='True' And the second query I tried is ,to return column namesSELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'SectionsAuthentication'And I want to ask if its possible to validate the conditions in the second query. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-29 : 02:21:11
|
ok. in that case what you could do is to unpivot the data and then do check likeSELECT ColumnNameFROM(SELECT *FROM(SELECT *FROM YourtableWHERE username = <your username value>AND password = <your password>)tUNPIVOT (Val FOR COlumnName IN ([Company],[DepartsAndDesgints],[CompDetails],...[bankdetails]))u)rWHERE Val='true' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-29 : 02:24:50
|
for making column list dynamic use logic likeDECLARE @columnList varchar(3000),@SQL varchar(max)SET @columnList = STUFF((SELECT ',[' + COLUMN_NAME + ']' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'SectionsAuthentication'AND DATATYPE = 'bit'),1,1,'')SELECT @SQL='SELECT ColumnNameFROM(SELECT *FROM(SELECT *FROM YourtableWHERE username = <your username value>AND password = <your password>)tUNPIVOT (Val FOR COlumnName IN (' + @columnlist + '))u)rWHERE Val=1'--PRINT(@SQL)EXEC(@SQL) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
SQLNEWBIZ
Starting Member
27 Posts |
Posted - 2013-04-29 : 02:34:29
|
THANKYOU Vishak .This one helped me to get my actual result.SELECT ColumnNameFROM(SELECT *FROM(SELECT *FROM YourtableWHERE username = <your username value>AND password = <your password>)tUNPIVOT (Val FOR COlumnName IN ([Company],[DepartsAndDesgints],[CompDetails],...[bankdetails]))u)rWHERE Val='true'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs[/quote] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-29 : 02:47:18
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|